Class TabularDataConverter
java.lang.Object
org.jolokia.service.serializer.object.TabularDataConverter
- All Implemented Interfaces:
Converter<TabularType>
Converter for TabularType objects. This converter transforms maps (in particular
JSON objects into TabularData values
according to the type specification defined in a TabularType.
The maps being converted come in 3 flavors:
- #1.
MXBeancompatibleMap/SortedMap: requiresTabularType.getRowType()to define two items:keyandvalue.TabularType.getIndexNames()should contain one item:key. If the type of item isSimpleType, we can convert any map, otherwise we expect maps that can be handled by flavors #2 and #3. - #2. non
@MXBeanmaps withindexNamesandvaluestop level fields: this is Jolokia-specific representation which directly representsTabularData, where eachrowis separate JSON object added to JSON array undervaluesfield of top-level map. This should be used ifTabularType.getIndexNames()point to fields inCompositeTypewhich are notsimple types. - #3. other non
@MXBeanmaps:TabularType.getIndexNames()are nested maps which eventually lead to the values. This representation is supported only ifTabularType.getIndexNames()point to fields inCompositeTypewhich areSimpleType.
- Since:
- 28.09.11
- Author:
- roland
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTabularDataConverter(ObjectToOpenTypeConverter pObjectToOpenTypeConverter) Constructor -
Method Summary
Modifier and TypeMethodDescriptionconvert(TabularType pType, Object pValue) Generic deserialization/conversion method, where:targetTypedescribes the desired type of the deserialized object (deserializers usually useClass, but we have other ways to specify the target type).valuecomes in some wire format (String or JSON), but we can also convert (which is wider term than deserialization) them from other types.static TabularTypecreateMXBeanTabularType(OpenType<?> keyType, OpenType<?> valueType) Helper method to create MXBean compatibleTabularTypewithkeyandvalueitems in itsCompositeTypeand singlekeyindex.protected voidensureStringKeys(Map<?, ?> pValue, Set<Integer> identities) Check if the genericMapuses only String-based keysprotected static StringgetMXBeanTypeName(OpenType<?> type) Get a name for givenOpenTypeto be used when creating composite type namesprotected booleanstatic booleanprotected <J extends org.jolokia.json.JSONStructure>
JConvert a value toJSONStructure.protected StringTrims non-null value before printing.
-
Field Details
-
forgiving
protected boolean forgiving -
objectToOpenTypeConverter
-
-
Constructor Details
-
TabularDataConverter
Constructor- Parameters:
pObjectToOpenTypeConverter- parent converter used for recursive conversion
-
-
Method Details
-
convert
Description copied from interface:ConverterGeneric deserialization/conversion method, where:
targetTypedescribes the desired type of the deserialized object (deserializers usually useClass, but we have other ways to specify the target type).valuecomes in some wire format (String or JSON), but we can also convert (which is wider term than deserialization) them from other types.
- Returns:
-
createMXBeanTabularType
public static TabularType createMXBeanTabularType(OpenType<?> keyType, OpenType<?> valueType) throws OpenDataException Helper method to create MXBean compatible
TabularTypewithkeyandvalueitems in itsCompositeTypeand singlekeyindex. The types of the key and value items may be any ofOpenType.If the type of the key is
Comparable, theTabularTypemaps toSortedMap. Otherwise it maps to unorderedMap.- Parameters:
keyType-valueType-- Returns:
- Throws:
OpenDataException- See Also:
-
isMXBeanMapWithSimpleKeys
Check if aTabularTypematches the mapping forMap<K, V>inMXBeanspecification. We also check if they keys are ofSimpleType, because of JSON serialization.- Parameters:
pType-- Returns:
-
getMXBeanTypeName
Get a name for givenOpenTypeto be used when creating composite type names- Parameters:
type-- Returns:
-
toJSON
Convert a value toJSONStructure. The given object must be either a valid JSON string or of typeJSONStructure, in which case it is returned directly if it matches desired target type.- Parameters:
pValue- the value to parse (or to return directly if it is aJSONStructure- Returns:
- the resulting value
-
ensureStringKeys
Check if the genericMapuses only String-based keys- Parameters:
pValue-identities- to track recursive instances - invoke first with empty set
-
toMap
-
isForgiving
protected boolean isForgiving()- Returns:
- whether I accept (and ignore) values that are not in the target type
-
trim
Trims non-null value before printing.- Parameters:
pValue-- Returns:
-