Class ObjectToJsonConverter
java.lang.Object
org.jolokia.service.serializer.json.ObjectToJsonConverter
A converter/serializer that transforms Java objects (JMX attribute values, JMX operation parameters
and return values) into a JSON representation. It delegates handling of supported types to
ObjectAccessor implementations.
Each ObjectAccessor gets a reference to this converter object so it can use it for a recursive
serialization of nested objects.
Additionally (since the dawn of Jolokia) this converter is used to set inner values of any objects.
Also by delegating to extractors which can handle particular object types. For example DateAccessor
can call Date.setTime(long).
- Since:
- Apr 19, 2009
- Author:
- roland
-
Field Summary
FieldsModifier and TypeFieldDescriptionClasses of the objects that can be returned directly as proper JSON types and can't be used with extra "path" do return part of the value.Simple types which are not proper JSON types (even if they seem to) but can be easily converted.Classes of the objects that can be returned directly as proper JSON types. -
Constructor Summary
ConstructorsConstructorDescriptionObjectToJsonConverter(ObjectToObjectConverter pObjectToObjectConverter, ObjectToOpenTypeConverter pObjectToOpenTypeConverter, org.jolokia.server.core.service.api.JolokiaContext pContext) Create a converter that can serialize objects into JSON representation -
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.
-
Field Details
-
JSON_TYPES
Classes of the objects that can be returned directly as proper JSON types. All other objects need to be converted in some way to proper JSON objects. -
JSON_BASIC_TYPES
Classes of the objects that can be returned directly as proper JSON types and can't be used with extra "path" do return part of the value. -
JSON_CONVERSIONS
Simple types which are not proper JSON types (even if they seem to) but can be easily converted.
-
-
Constructor Details
-
ObjectToJsonConverter
public ObjectToJsonConverter(ObjectToObjectConverter pObjectToObjectConverter, ObjectToOpenTypeConverter pObjectToOpenTypeConverter, org.jolokia.server.core.service.api.JolokiaContext pContext) Create a converter that can serialize objects into JSON representation- Parameters:
pObjectToObjectConverter- used when setting valuespObjectToOpenTypeConverter- used when convertingTabularDatapContext-JolokiaContextused to loadObjectAccessorservices
-
-
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
-