Class GenericJson

  • All Implemented Interfaces:
    java.lang.Cloneable, java.util.Map<java.lang.String,​java.lang.Object>
    Direct Known Subclasses:
    AbstractJsonFactoryTest.AnimalGenericJson, AbstractJsonFactoryTest.ExtendsGenericJson, JsonWebToken.Header, JsonWebToken.Payload

    public class GenericJson
    extends GenericData
    implements java.lang.Cloneable
    Generic JSON data that stores all unknown key name/value pairs.

    Subclasses can declare fields for known data keys using the Key annotation. Each field can be of any visibility (private, package private, protected, or public) and must not be static. null unknown data key names are not allowed, but null data values are allowed.

    Implementation is not thread-safe. For a thread-safe choice instead use an implementation of ConcurrentMap.

    Since:
    1.0
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private JsonFactory jsonFactory
      JSON factory or null for none.
    • Constructor Summary

      Constructors 
      Constructor Description
      GenericJson()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      GenericJson clone()
      Makes a "deep" clone of the generic data, in which the clone is completely independent of the original.
      JsonFactory getFactory()
      Returns the JSON factory or null for none.
      GenericJson set​(java.lang.String fieldName, java.lang.Object value)
      Sets the given field value (may be null) for the given field name.
      void setFactory​(JsonFactory factory)
      Sets the JSON factory or null for none.
      java.lang.String toPrettyString()
      Returns a pretty-printed serialized JSON string representation or toString() if getFactory() is null.
      java.lang.String toString()  
      • Methods inherited from class java.util.AbstractMap

        clear, containsKey, containsValue, isEmpty, keySet, size, values
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Field Detail

      • jsonFactory

        private JsonFactory jsonFactory
        JSON factory or null for none.
    • Constructor Detail

      • GenericJson

        public GenericJson()
    • Method Detail

      • getFactory

        public final JsonFactory getFactory()
        Returns the JSON factory or null for none.
        Since:
        1.6
      • setFactory

        public final void setFactory​(JsonFactory factory)
        Sets the JSON factory or null for none.
        Since:
        1.6
      • toPrettyString

        public java.lang.String toPrettyString()
                                        throws java.io.IOException
        Returns a pretty-printed serialized JSON string representation or toString() if getFactory() is null.
        Throws:
        java.io.IOException
        Since:
        1.6
      • clone

        public GenericJson clone()
        Description copied from class: GenericData
        Makes a "deep" clone of the generic data, in which the clone is completely independent of the original.
        Overrides:
        clone in class GenericData
      • set

        public GenericJson set​(java.lang.String fieldName,
                               java.lang.Object value)
        Description copied from class: GenericData
        Sets the given field value (may be null) for the given field name. Any existing value for the field will be overwritten. It may be more slightly more efficient than GenericData.put(String, Object) because it avoids accessing the field's original value.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Overrides:
        set in class GenericData