Class TabularDataConverter

java.lang.Object
org.jolokia.service.serializer.object.TabularDataConverter
All Implemented Interfaces:
Converter<TabularType>

public class TabularDataConverter extends Object

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:

Since:
28.09.11
Author:
roland
  • Field Details

    • forgiving

      protected boolean forgiving
    • objectToOpenTypeConverter

      protected final ObjectToOpenTypeConverter objectToOpenTypeConverter
  • Constructor Details

    • TabularDataConverter

      public TabularDataConverter(ObjectToOpenTypeConverter pObjectToOpenTypeConverter)
      Constructor
      Parameters:
      pObjectToOpenTypeConverter - parent converter used for recursive conversion
  • Method Details

    • convert

      public Object convert(TabularType pType, Object pValue)
      Description copied from interface: Converter

      Generic deserialization/conversion method, where:

      • targetType describes the desired type of the deserialized object (deserializers usually use Class, but we have other ways to specify the target type).
      • value comes 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 TabularType with key and value items in its CompositeType and single key index. The types of the key and value items may be any of OpenType.

      If the type of the key is Comparable, the TabularType maps to SortedMap. Otherwise it maps to unordered Map.

      Parameters:
      keyType -
      valueType -
      Returns:
      Throws:
      OpenDataException
      See Also:
    • isMXBeanMapWithSimpleKeys

      public static boolean isMXBeanMapWithSimpleKeys(TabularType pType)
      Check if a TabularType matches the mapping for Map<K, V> in MXBean specification. We also check if they keys are of SimpleType, because of JSON serialization.
      Parameters:
      pType -
      Returns:
    • getMXBeanTypeName

      protected static String getMXBeanTypeName(OpenType<?> type)
      Get a name for given OpenType to be used when creating composite type names
      Parameters:
      type -
      Returns:
    • toJSON

      protected <J extends org.jolokia.json.JSONStructure> J toJSON(Object pValue, Class<J> jsonType)
      Convert a value to JSONStructure. The given object must be either a valid JSON string or of type JSONStructure, 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 a JSONStructure
      Returns:
      the resulting value
    • ensureStringKeys

      protected void ensureStringKeys(Map<?,?> pValue, Set<Integer> identities)
      Check if the generic Map uses only String-based keys
      Parameters:
      pValue -
      identities - to track recursive instances - invoke first with empty set
    • toMap

      protected Map<String,Object> toMap(Object pValue)
    • isForgiving

      protected boolean isForgiving()
      Returns:
      whether I accept (and ignore) values that are not in the target type
    • trim

      protected String trim(String pValue)
      Trims non-null value before printing.
      Parameters:
      pValue -
      Returns: