Class JSONMapping<JAVAT,​JSONT>

  • Type Parameters:
    JAVAT - Java type
    JSONT - JSON type

    public abstract class JSONMapping<JAVAT,​JSONT>
    extends java.lang.Object

    Warning: Work in progress

    This is an early prototype of a way to add own type mappings to the json modeller. An implementation of this abstract class can be added to the JSONCodecConfiguration as 'mapping'. A provided mapping gets priority over generic mappings. Currently, custom mappings can be provided for any combination of Java and JSON type. However JSON types are limited to the value types of the JSON model, such as JSONObject, JSONArray, Long and Double for JSON numbers, String or Boolean. A mapping rule is always selected by its Java type first. However, there can exist multiple mappings for the same type but different JSON types. When encoding to JSON, the modeller will then select one by random (since they are stored in a hash map). When decoding from JSON to Java, the modeller will lookup the mapping with matching tuple of Java and JSON type.
    Author:
    homac
    • Constructor Summary

      Constructors 
      Constructor Description
      JSONMapping​(java.lang.Class<JAVAT> javaType, java.lang.Class<JSONT> jsonType)  
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      abstract JAVAT toJava​(JSONModeller modeller, JSONT jsonValue)
      Instantiate a new Java object of type JAVAT and initialise it from JSON value of type JSONT.
      abstract void toJava​(JSONModeller modeller, JSONT jsonAny, JAVAT targetObject)
      Initialise given javaValue from give jsonValue.
      abstract JSONT toJson​(JSONModeller modeller, JAVAT javaValue)
      Implementation maps given javaValue to a valid JSON value.
      • Methods inherited from class java.lang.Object

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

      • javaType

        public final java.lang.Class<JAVAT> javaType
      • jsonType

        public final java.lang.Class<JSONT> jsonType
    • Constructor Detail

      • JSONMapping

        public JSONMapping​(java.lang.Class<JAVAT> javaType,
                           java.lang.Class<JSONT> jsonType)