Class JsonCodec<T>


  • public abstract class JsonCodec<T>
    extends java.lang.Object
    Abstraction of a codec capable for encoding/decoding arbitrary objects to/from JSON.
    • Constructor Summary

      Constructors 
      Constructor Description
      JsonCodec()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<T> decode​(com.fasterxml.jackson.databind.node.ArrayNode json, CodecContext context)
      Decodes the specified JSON array into a collection of entities.
      T decode​(com.fasterxml.jackson.databind.node.ObjectNode json, CodecContext context)
      Decodes the specified entity from JSON.
      com.fasterxml.jackson.databind.node.ArrayNode encode​(java.lang.Iterable<T> entities, CodecContext context)
      Encodes the collection of the specified entities.
      com.fasterxml.jackson.databind.node.ObjectNode encode​(T entity, CodecContext context)
      Encodes the specified entity into JSON.
      protected static com.fasterxml.jackson.databind.node.ObjectNode get​(com.fasterxml.jackson.databind.JsonNode parent, int childIndex)
      Gets a child Object Node from a parent by index.
      protected static com.fasterxml.jackson.databind.node.ObjectNode get​(com.fasterxml.jackson.databind.node.ObjectNode parent, java.lang.String childName)
      Gets a child Object Node from a parent by name.
      • Methods inherited from class java.lang.Object

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

      • JsonCodec

        public JsonCodec()
    • Method Detail

      • encode

        public com.fasterxml.jackson.databind.node.ObjectNode encode​(T entity,
                                                                     CodecContext context)
        Encodes the specified entity into JSON.
        Parameters:
        entity - entity to encode
        context - encoding context
        Returns:
        JSON node
        Throws:
        java.lang.UnsupportedOperationException - if the codec does not support encode operations
      • decode

        public T decode​(com.fasterxml.jackson.databind.node.ObjectNode json,
                        CodecContext context)
        Decodes the specified entity from JSON.
        Parameters:
        json - JSON to decode
        context - decoding context
        Returns:
        decoded entity
        Throws:
        java.lang.UnsupportedOperationException - if the codec does not support decode operations
      • encode

        public com.fasterxml.jackson.databind.node.ArrayNode encode​(java.lang.Iterable<T> entities,
                                                                    CodecContext context)
        Encodes the collection of the specified entities.
        Parameters:
        entities - collection of entities to encode
        context - encoding context
        Returns:
        JSON array
        Throws:
        java.lang.UnsupportedOperationException - if the codec does not support encode operations
      • decode

        public java.util.List<T> decode​(com.fasterxml.jackson.databind.node.ArrayNode json,
                                        CodecContext context)
        Decodes the specified JSON array into a collection of entities.
        Parameters:
        json - JSON array to decode
        context - decoding context
        Returns:
        collection of decoded entities
        Throws:
        java.lang.UnsupportedOperationException - if the codec does not support decode operations
      • get

        protected static com.fasterxml.jackson.databind.node.ObjectNode get​(com.fasterxml.jackson.databind.node.ObjectNode parent,
                                                                            java.lang.String childName)
        Gets a child Object Node from a parent by name. If the child is not found or does nor represent an object, null is returned.
        Parameters:
        parent - parent object
        childName - name of child to query
        Returns:
        child object if found, null if not found or if not an object
      • get

        protected static com.fasterxml.jackson.databind.node.ObjectNode get​(com.fasterxml.jackson.databind.JsonNode parent,
                                                                            int childIndex)
        Gets a child Object Node from a parent by index. If the child is not found or does nor represent an object, null is returned.
        Parameters:
        parent - parent object
        childIndex - index of child to query
        Returns:
        child object if found, null if not found or if not an object