Class ObjectToJsonConverter

java.lang.Object
org.jolokia.service.serializer.json.ObjectToJsonConverter

public final class ObjectToJsonConverter extends Object
A converter which converts attribute and return values into a JSON representation. It uses certain handlers for this which are registered in the constructor.

Each handler gets a reference to this converter object so that it can use it for a recursive solution of nested objects.

Since:
Apr 19, 2009
Author:
roland
  • Constructor Details

    • ObjectToJsonConverter

      public ObjectToJsonConverter(StringToObjectConverter pStringToObjectConverter)
    • ObjectToJsonConverter

      public ObjectToJsonConverter(StringToObjectConverter pStringToObjectConverter, org.jolokia.server.core.service.api.JolokiaContext context)
      New object-to-json converter
      Parameters:
      pStringToObjectConverter - used when setting values
  • Method Details

    • serialize

      public Object serialize(Object pValue, List<String> pPathParts, org.jolokia.server.core.service.serializer.SerializeOptions pOptions) throws AttributeNotFoundException
      Convert the return value to a JSON object.
      Parameters:
      pValue - the value to convert
      pPathParts - path parts to use for extraction
      pOptions - options used for parsing
      Returns:
      the converter object. This either a subclass of JSONStructure or a basic data type like String or Long.
      Throws:
      AttributeNotFoundException - if within a path an attribute could not be found
    • setInnerValue

      public Object setInnerValue(Object pOuterObject, Object pNewValue, List<String> pPathParts) throws AttributeNotFoundException, IllegalAccessException, InvocationTargetException
      Set an inner value of a complex object. A given path must point to the attribute/index to set within the outer object.
      Parameters:
      pOuterObject - the object to dive in
      pNewValue - the value to set
      pPathParts - the path within the outer object. This object will be modified and must be a modifiable list.
      Returns:
      the old value
      Throws:
      AttributeNotFoundException
      IllegalAccessException
      InvocationTargetException
    • extractObject

      public Object extractObject(Object pValue, Deque<String> pPathParts, boolean pJsonify) throws AttributeNotFoundException
      Related to extractObjectWithContext(java.lang.Object, java.util.Deque<java.lang.String>, org.jolokia.server.core.service.serializer.SerializeOptions, boolean) except that it does not set up a context. This method is called back from the various extractors to recursively continue the extraction, hence it is public.

      This method must not be used as entry point for serialization. Use serialize(Object, List, SerializeOptions) or setInnerValue(Object, Object, List) instead.

      Parameters:
      pValue - value to extract from
      pPathParts - stack for diving into the object
      pJsonify - whether a JSON representation JSONObject
      Returns:
      extracted object either in native format or as JSONObject
      Throws:
      AttributeNotFoundException - if an attribute is not found during traversal
    • getValueFaultHandler

      public org.jolokia.server.core.service.serializer.ValueFaultHandler getValueFaultHandler()
      Get the fault handler used for dealing with exceptions during value extraction.
      Returns:
      the fault handler