Module io.avaje.jex

Class JacksonJsonService

java.lang.Object
io.avaje.jex.core.json.JacksonJsonService
All Implemented Interfaces:
JexExtension, JsonService

public final class JacksonJsonService extends Object implements JsonService
Jackson JsonService
  • Constructor Details

    • JacksonJsonService

      public JacksonJsonService()
      Create with defaults for Jackson
    • JacksonJsonService

      public JacksonJsonService(com.fasterxml.jackson.databind.ObjectMapper mapper)
      Create with a Jackson instance that might have custom configuration.
  • Method Details

    • fromJson

      public <T> T fromJson(Type type, InputStream is)
      Description copied from interface: JsonService
      Deserializes a json input stream and deserializes it into a Java object of the specified type.
      Specified by:
      fromJson in interface JsonService
      Parameters:
      type - the Type object of the desired type
      is - the input stream containing the JSON data
      Returns:
      the deserialized object
    • fromJson

      public <T> T fromJson(Type type, byte[] data)
      Description copied from interface: JsonService
      Deserializes a json byte[] into a Java object of the specified type.
      Specified by:
      fromJson in interface JsonService
      Parameters:
      type - the Type object of the desired type
      data - the byte[] containing the JSON data
      Returns:
      the deserialized object
    • toJson

      public void toJson(Object bean, OutputStream os)
      Description copied from interface: JsonService
      **Writes a Java Object as JSON to an OutputStream**

      Serializes a Java object into JSON format and writes the resulting JSON to the specified output stream.

      Specified by:
      toJson in interface JsonService
      Parameters:
      bean - the Java object to be serialized
      os - the output stream to write the JSON data to
    • toJsonString

      public String toJsonString(Object bean)
      Description copied from interface: JsonService
      **Writes a Java Object as a JSON string**

      Serializes a Java object into JSON string format and writes the resulting JSON to the specified output stream.

      Specified by:
      toJsonString in interface JsonService
      Parameters:
      bean - the Java object to be serialized
      Returns:
      the serialized JSON string
    • toJsonStream

      public <T> void toJsonStream(Iterator<T> iterator, OutputStream os)
      Description copied from interface: JsonService
      Serializes a stream of Java objects into a JSON-Stream format, using the x-json-stream media type. Each object in the stream is serialized as a separate JSON object, and the objects are separated by newlines.
      Specified by:
      toJsonStream in interface JsonService
      Parameters:
      iterator - the stream of objects to be serialized
      os - the output stream to write the JSON-Stream data to