Module io.avaje.jex

Class JsonbJsonService

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

public final class JsonbJsonService extends Object implements JsonService
Provides JsonService using avaje-jsonb.
  • Constructor Details

    • JsonbJsonService

      public JsonbJsonService()
      Create with defaults for Jsonb.
    • JsonbJsonService

      public JsonbJsonService(io.avaje.jsonb.Jsonb jsonb)
      Create with a Jsonb instance that might have custom configuration.
  • Method Details

    • jsonRead

      public <T> T jsonRead(Class<T> clazz, InputStream is)
      Description copied from interface: JsonService
      **Reads JSON from an InputStream**

      Reads a JSON-formatted input stream and deserializes it into a Java object of the specified type.

      Specified by:
      jsonRead in interface JsonService
      Parameters:
      clazz - the Class object of the desired type
      is - the input stream containing the JSON data
      Returns:
      the deserialized object
    • jsonWrite

      public void jsonWrite(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:
      jsonWrite in interface JsonService
      Parameters:
      bean - the Java object to be serialized
      os - the output stream to write the JSON data to
    • jsonWriteStream

      public <T> void jsonWriteStream(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:
      jsonWriteStream in interface JsonService
      Parameters:
      iterator - the stream of objects to be serialized
      os - the output stream to write the JSON-Stream data to