Class JsonCodec

java.lang.Object
com.github.cafapi.common.codecs.json.JsonCodec
All Implemented Interfaces:
Codec, Decoder

@FileExtensions({"","json"}) public class JsonCodec extends Object implements Codec
Implementation of Codec that supports serialisation and deserialisation to and form JSON format.
  • Constructor Details

    • JsonCodec

      public JsonCodec()
  • Method Details

    • deserialise

      public <T> T deserialise(byte[] data, Class<T> clazz, DecodeMethod method) throws CodecException
      Description copied from interface: Codec
      Deserialise the given data into the specified class.
      Specified by:
      deserialise in interface Codec
      Type Parameters:
      T - the class the serialised data represents
      Parameters:
      data - the serialised data
      clazz - the class the serialised data represents
      method - specifies whether to use strict or lenient decoding during deserialisation
      Returns:
      an instance of the class specified represented by the data
      Throws:
      CodecException - if the data could not be deserialised
    • deserialise

      public <T> T deserialise(InputStream stream, Class<T> clazz, DecodeMethod method) throws CodecException
      Description copied from interface: Codec
      Deserialise the given data into the specified class using the default decode method.
      Specified by:
      deserialise in interface Codec
      Type Parameters:
      T - the class the serialised data represents
      Parameters:
      stream - the serialised data as a stream
      clazz - the class the serialised data represents
      method - specifies whether to use strict or lenient decoding during deserialisation
      Returns:
      an instance of the class specified represented by the data
      Throws:
      CodecException - if the data could not be deserialised
    • serialise

      public byte[] serialise(Object object) throws CodecException
      Description copied from interface: Codec
      Serialise the given object into a byte data form.
      Specified by:
      serialise in interface Codec
      Parameters:
      object - the object to serialise
      Returns:
      the serialised data of the given object
      Throws:
      CodecException - if the object could not be serialised
    • getMapper

      protected com.fasterxml.jackson.databind.ObjectMapper getMapper(DecodeMethod method)