Class CollectionAccessor

java.lang.Object
org.jolokia.service.serializer.json.CollectionAccessor
All Implemented Interfaces:
ObjectAccessor

public class CollectionAccessor extends Object implements 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 Details

    • CollectionAccessor

      public CollectionAccessor()
  • Method Details

    • getType

      public Class<?> getType()
      Description copied from interface: ObjectAccessor
      Gets a class of supported objects.
      Specified by:
      getType in interface ObjectAccessor
      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 actual Collection may not be ordered and the index is simulated by iterator counter.
      Specified by:
      extractObject in interface ObjectAccessor
      Parameters:
      pConverter - the global converter to convert inner values and get serialization options
      pCollection - the value to convert (must be a Collection)
      pPathParts - if not empty, top value may be an index into the iterator loop over the collection and remaining parts are passed recursively
      pJsonify - whether to convert the collection into a JSONArray or its element to a relevant JSON representation
      Returns:
      the extracted object or entire collection when the pPathParts stack is empty
      Throws:
      AttributeNotFoundException - if the index is not specified as non-negative integer
      IndexOutOfBoundsException - if an index is used which points outside the given list
    • canSetValue

      public boolean canSetValue()
      Description copied from interface: ObjectAccessor
      Whether this accessor can be used to set a value inside (directly or nested) a value of given class.
      Specified by:
      canSetValue in interface ObjectAccessor
      Returns:
      true if 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:
      setObjectValue in interface ObjectAccessor
      Parameters:
      pConverter - Converter used to convert the value being set to a class of the accessed attribute
      pObject - object on which to set the value
      pAttribute - attribute of the object to set. (For arrays or lists it should be an index.)
      pValue - the new value to set after conversion
      Returns:
      the old value of the changed attribute
      Throws:
      IllegalAccessException - if the attribute to set to is not accessible
      InvocationTargetException - reflection error