Class ObjectToJsonConverter
java.lang.Object
org.jolokia.service.serializer.json.ObjectToJsonConverter
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 Summary
ConstructorsConstructorDescriptionObjectToJsonConverter(StringToObjectConverter pStringToObjectConverter) ObjectToJsonConverter(StringToObjectConverter pStringToObjectConverter, org.jolokia.server.core.service.api.JolokiaContext context) New object-to-json converter -
Method Summary
Modifier and TypeMethodDescriptionextractObject(Object pValue, Deque<String> pPathParts, boolean pJsonify) Related toextractObjectWithContext(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.org.jolokia.server.core.service.serializer.ValueFaultHandlerGet the fault handler used for dealing with exceptions during value extraction.serialize(Object pValue, List<String> pPathParts, org.jolokia.server.core.service.serializer.SerializeOptions pOptions) Convert the return value to a JSON object.setInnerValue(Object pOuterObject, Object pNewValue, List<String> pPathParts) Set an inner value of a complex object.
-
Constructor Details
-
ObjectToJsonConverter
-
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 convertpPathParts- path parts to use for extractionpOptions- options used for parsing- Returns:
- the converter object. This either a subclass of
JSONStructureor 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 inpNewValue- the value to setpPathParts- the path within the outer object. This object will be modified and must be a modifiable list.- Returns:
- the old value
- Throws:
AttributeNotFoundExceptionIllegalAccessExceptionInvocationTargetException
-
extractObject
public Object extractObject(Object pValue, Deque<String> pPathParts, boolean pJsonify) throws AttributeNotFoundException Related toextractObjectWithContext(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)orsetInnerValue(Object, Object, List)instead.- Parameters:
pValue- value to extract frompPathParts- stack for diving into the objectpJsonify- whether a JSON representationJSONObject- 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
-