Class NestedJsonArray<P extends ExtensibleJsonPojo,​C extends DbPojo>

java.lang.Object
tenapull.data.deserialize.NestedJsonArray<P,​C>
Type Parameters:
P - The parent object of the ORM, which owns the list of child objects
C - The child objects of the list, which are embedded inside the intermediate JSON wrapper represented by an implementation of this class
Direct Known Subclasses:
RefInformation, RefValues, ScanPrioritization, SeverityCount

@MappedSuperclass
public abstract class NestedJsonArray<P extends ExtensibleJsonPojo,​C extends DbPojo>
extends java.lang.Object
Used to "wrap" an array of objects inside an intermediate JSON object, even though the original list belongs to the parent object. This class represents the intermediate object, which does not represent any entity in the ORM, but which is needed for serialization/deserialization. Any additional properties of this object (as implemented by sub classes) besides the wrapped array will typically be stored inside the parent object, which IS a part of the ORM.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static java.lang.String EXTRA_JSON_KEY_IN_PARENT
    The key used for the ExtraJson map in the parent object, if there is any unexpected JSON in the wrapper object.
  • Constructor Summary

    Constructors 
    Constructor Description
    NestedJsonArray()  
  • Method Summary

    Modifier and Type Method Description
    void checkExtraJsonPut​(java.lang.String key, java.lang.Object value)
    Double checks that the extra json between the wrapper and parents are correctly synchronized
    void clearParent()
    When the parent is unset, the shared list of child objects must be de-coupled between the parent and wrapper, so a modification in one list does not cause a modification in the other.
    abstract java.lang.String getArrayKey()
    Method that must be implemented by concrete subclasses, providing the JSON key for the array this object wraps.
    java.util.Map<java.lang.String,​com.fasterxml.jackson.databind.JsonNode> getExtraJson()
    Converts the ObjectNode representing the wrapper's extra json (usually obtained from the parent entity) into a Map for use by the serializer
    protected java.util.List<C> getList()
    Gets the list of child entities
    P getParent()
    Gets the parent POJO object
    protected abstract java.util.List<C> getParentList​(P parent)
    Method that must be implemented by concrete subclasses, which grabs the list of child entities from the parent object
    java.util.Map<java.lang.String,​com.fasterxml.jackson.databind.JsonNode> jsonAnyGetterForParent()
    A utility for the parent entity to invoke when providing its ExtraJson map to a serializer.
    void putExtraJson​(java.lang.String key, java.lang.Object value)
    Puts an additional key-value pair into the ObjectNode representing the ExtraJson for this wrapper
    void putFieldsIntoParent​(P parent)
    Take the extra json deserialized into this wrapper and puts it into the parent for long-term persistence in the DB/ORM.
    void setList​(java.util.List<C> list)
    Sets the list of child entities, and also sets it in the parent if a parent has been set.
    protected abstract void setParentList​(P parent, java.util.List<C> list)
    Method that must be implemented by concrete subclasses, which sets the list of child entities in the parent object
    void takeFieldsFromParent​(P parent)
    Obtains stored ExtraJson from the parent, when reconstructing this wrapper from the DB/ORM

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • EXTRA_JSON_KEY_IN_PARENT

      public static final java.lang.String EXTRA_JSON_KEY_IN_PARENT
      The key used for the ExtraJson map in the parent object, if there is any unexpected JSON in the wrapper object. This will be appended with the class name of the wrapper implementation
      See Also:
      Constant Field Values
  • Constructor Details

  • Method Details

    • getArrayKey

      public abstract java.lang.String getArrayKey()
      Method that must be implemented by concrete subclasses, providing the JSON key for the array this object wraps.
      Returns:
    • getParentList

      protected abstract java.util.List<C> getParentList​(@NotNull P parent)
      Method that must be implemented by concrete subclasses, which grabs the list of child entities from the parent object
      Parameters:
      parent - the new parent object which owns the list of children
      Returns:
      the list of children fetched from the parent
    • setParentList

      protected abstract void setParentList​(@NotNull P parent, java.util.List<C> list)
      Method that must be implemented by concrete subclasses, which sets the list of child entities in the parent object
      Parameters:
      parent - the parent object which owns the list of children
      list - the new list to set in the parent object
    • getParent

      public P getParent()
      Gets the parent POJO object
      Returns:
      the parent POJO object
    • getExtraJson

      public java.util.Map<java.lang.String,​com.fasterxml.jackson.databind.JsonNode> getExtraJson()
      Converts the ObjectNode representing the wrapper's extra json (usually obtained from the parent entity) into a Map for use by the serializer
      Returns:
      a Map of keys and JsonNodes, for extra json
    • getList

      protected java.util.List<C> getList()
      Gets the list of child entities
      Returns:
      the list of child entities
    • setList

      public void setList​(java.util.List<C> list)
      Sets the list of child entities, and also sets it in the parent if a parent has been set. Includes an initial check to prevent infinite recursion between the parent and wrapper setting each other's lists.
      Parameters:
      list - the list of child entities
    • putExtraJson

      public void putExtraJson​(java.lang.String key, java.lang.Object value)
      Puts an additional key-value pair into the ObjectNode representing the ExtraJson for this wrapper
      Parameters:
      key -
      value -
    • takeFieldsFromParent

      public void takeFieldsFromParent​(P parent) throws java.lang.ClassCastException
      Obtains stored ExtraJson from the parent, when reconstructing this wrapper from the DB/ORM
      Parameters:
      parent - the new parent entity to obtain the extra json from
      Throws:
      java.lang.ClassCastException - if the node returned from the parent is not an ObjectNode
    • putFieldsIntoParent

      public void putFieldsIntoParent​(P parent)
      Take the extra json deserialized into this wrapper and puts it into the parent for long-term persistence in the DB/ORM.
      Parameters:
      parent -
    • clearParent

      public void clearParent()
      When the parent is unset, the shared list of child objects must be de-coupled between the parent and wrapper, so a modification in one list does not cause a modification in the other.
    • jsonAnyGetterForParent

      public java.util.Map<java.lang.String,​com.fasterxml.jackson.databind.JsonNode> jsonAnyGetterForParent()
      A utility for the parent entity to invoke when providing its ExtraJson map to a serializer. This method makes a copy of the parent's map and removes the wrapper's extra json so it doesn't end up being serialized in the parent also.
      Returns:
      a copy of the parent's extra json map with the wrapper's extra json removed
    • checkExtraJsonPut

      public void checkExtraJsonPut​(java.lang.String key, java.lang.Object value)
      Double checks that the extra json between the wrapper and parents are correctly synchronized
      Parameters:
      key -
      value -