Class GsonJsonHandler

java.lang.Object
com.caplin.datasource.messaging.json.GsonJsonHandler
All Implemented Interfaces:
JsonHandler<com.google.gson.JsonElement>

public class GsonJsonHandler extends Object implements JsonHandler<com.google.gson.JsonElement>
  • Constructor Summary

    Constructors
    Constructor
    Description
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    com.google.gson.JsonElement
    diff(com.google.gson.JsonElement source, com.google.gson.JsonElement target)
    Creates a JSON patch of the difference between two JSON tree representations
    format(com.google.gson.JsonElement jsonElement)
    Formats a JSON tree representation of an object to a JSON String.
    com.google.gson.JsonElement
    parse(String jsonText)
    Parses a JSON text into a JSON tree representation used by the underlying JSON library.
    com.google.gson.JsonElement
    patch(com.google.gson.JsonElement source, com.google.gson.JsonElement diff)
    Updates a JSON tree representation with a JSON patch
    com.google.gson.JsonElement
    toJsonTree(Object userObject)
    Serializes a plain Java object (POJO) to a JSON tree representation used by the underlying JSON library.
    toObject(com.google.gson.JsonElement jsonElement, Class userType)
    Deserializes a JSON tree representation to a plain Java object

    Methods inherited from class java.lang.Object

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

    • GsonJsonHandler

      public GsonJsonHandler()
    • GsonJsonHandler

      public GsonJsonHandler(Logger logger)
  • Method Details

    • toJsonTree

      public com.google.gson.JsonElement toJsonTree(Object userObject)
      Description copied from interface: JsonHandler
      Serializes a plain Java object (POJO) to a JSON tree representation used by the underlying JSON library.
      Specified by:
      toJsonTree in interface JsonHandler<com.google.gson.JsonElement>
      Parameters:
      userObject - a plain Java object
      Returns:
      a JSON tree representation of the object
    • toObject

      public Object toObject(com.google.gson.JsonElement jsonElement, Class userType) throws Exception
      Description copied from interface: JsonHandler
      Deserializes a JSON tree representation to a plain Java object
      Specified by:
      toObject in interface JsonHandler<com.google.gson.JsonElement>
      Parameters:
      jsonElement - a JSON tree representation of the object
      userType - the type of the object to deserialize into
      Returns:
      a new object of type userType
      Throws:
      Exception - if deserialization fails
    • parse

      public com.google.gson.JsonElement parse(String jsonText) throws Exception
      Description copied from interface: JsonHandler
      Parses a JSON text into a JSON tree representation used by the underlying JSON library.
      Specified by:
      parse in interface JsonHandler<com.google.gson.JsonElement>
      Parameters:
      jsonText - the JSON text to parse
      Returns:
      a JSON tree representation of the JSON text
      Throws:
      Exception - if the parsing fails
    • format

      public String format(com.google.gson.JsonElement jsonElement) throws Exception
      Description copied from interface: JsonHandler
      Formats a JSON tree representation of an object to a JSON String.
      Specified by:
      format in interface JsonHandler<com.google.gson.JsonElement>
      Parameters:
      jsonElement - a JSON tree representation of an object
      Returns:
      the JSON String
      Throws:
      Exception - if formatting fails
    • diff

      public com.google.gson.JsonElement diff(com.google.gson.JsonElement source, com.google.gson.JsonElement target)
      Description copied from interface: JsonHandler
      Creates a JSON patch of the difference between two JSON tree representations
      Specified by:
      diff in interface JsonHandler<com.google.gson.JsonElement>
      Parameters:
      source - a JSON tree representation of the source object
      target - a JSON tree representation of the target object
      Returns:
      a JSON tree representation of the JSON patch needed to patch source to create target.
    • patch

      public com.google.gson.JsonElement patch(com.google.gson.JsonElement source, com.google.gson.JsonElement diff) throws Exception
      Description copied from interface: JsonHandler
      Updates a JSON tree representation with a JSON patch
      Specified by:
      patch in interface JsonHandler<com.google.gson.JsonElement>
      Parameters:
      source - a JSON tree representation of the source object
      diff - a JSON tree representation of the JSON patch
      Returns:
      the updated, patched object
      Throws:
      Exception - if the patch fails