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

    • fromJson

      public <T> T fromJson(Type clazz, 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:
      clazz - 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 clazz, 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:
      clazz - 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