Class CollectionAccessor
java.lang.Object
org.jolokia.service.serializer.json.CollectionAccessor
- All Implemented Interfaces:
ObjectAccessor
Accessor used for arbitrary collections. They are simply converted into
JSONArray, although
the order is arbitrary. Setting to a collection is not allowed.
This accessor must be called after all more specialized extractors (like the ListAccessor or ArrayAccessor).- Since:
- 18.10.11
- Author:
- roland
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanWhether this accessor can be used to set a value inside (directly or nested) a value ofgiven class.extractObject(ObjectToJsonConverter pConverter, Object pCollection, Deque<String> pPathParts, boolean pJsonify) Converts a collection to an JSON array.Class<?>getType()Gets a class of supported objects.Setting of an object value is not supported for the collection converterMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jolokia.service.serializer.json.ObjectAccessor
extractString, supportsStringConversion
-
Constructor Details
-
CollectionAccessor
public CollectionAccessor()
-
-
Method Details
-
getType
Description copied from interface:ObjectAccessorGets a class of supported objects.- Specified by:
getTypein interfaceObjectAccessor- Returns:
- supported type of the objects handled by this accessor
-
extractObject
public Object extractObject(ObjectToJsonConverter pConverter, Object pCollection, Deque<String> pPathParts, boolean pJsonify) throws AttributeNotFoundException Converts a collection to an JSON array. Element at given index can be extracted, but the actualCollectionmay not be ordered and the index is simulated by iterator counter.- Specified by:
extractObjectin interfaceObjectAccessor- Parameters:
pConverter- the global converter to convert inner values and get serialization optionspCollection- the value to convert (must be aCollection)pPathParts- if not empty, top value may be an index into the iterator loop over the collection and remaining parts are passed recursivelypJsonify- whether to convert the collection into aJSONArrayor its element to a relevant JSON representation- Returns:
- the extracted object or entire collection when the
pPathPartsstack is empty - Throws:
AttributeNotFoundException- if the index is not specified as non-negative integerIndexOutOfBoundsException- if an index is used which points outside the given list
-
canSetValue
public boolean canSetValue()Description copied from interface:ObjectAccessorWhether this accessor can be used to set a value inside (directly or nested) a value ofgiven class.- Specified by:
canSetValuein interfaceObjectAccessor- Returns:
trueif this extractor can be used to set inner values.
-
setObjectValue
public Object setObjectValue(Converter<String> pConverter, Object pObject, String pAttribute, Object pValue) throws IllegalAccessException, InvocationTargetException Setting of an object value is not supported for the collection converter- Specified by:
setObjectValuein interfaceObjectAccessor- Parameters:
pConverter-Converterused to convert the value being set to a class of the accessed attributepObject- object on which to set the valuepAttribute- attribute of the object to set. (For arrays or lists it should be an index.)pValue- the new value to set afterconversion- Returns:
- the old value of the changed attribute
- Throws:
IllegalAccessException- if the attribute to set to is not accessibleInvocationTargetException- reflection error
-