Interface JsonService

All Superinterfaces:
JexExtension
All Known Implementing Classes:
JacksonJsonService, JsonbJsonService

public non-sealed interface JsonService extends JexExtension
Service responsible for handling JSON-based request and response bodies.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    fromJson(Type type, byte[] data)
    Deserializes a json byte[] into a Java object of the specified type.
    <T> T
    Deserializes a json input stream and deserializes it into a Java object of the specified type.
    void
    **Writes a Java Object as JSON to an OutputStream**
    default <E> void
    Serializes a stream of Java objects into a JSON-Stream format, using the x-json-stream media type.
    **Writes a Java Object as a JSON string**
  • Method Details

    • toJson

      void toJson(Object bean, OutputStream os)
      **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.

      Parameters:
      bean - the Java object to be serialized
      os - the output stream to write the JSON data to
    • toJsonString

      String toJsonString(Object bean)
      **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.

      Parameters:
      bean - the Java object to be serialized
      Returns:
      the serialized JSON string
    • fromJson

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

      <T> T fromJson(Type type, byte[] data)
      Deserializes a json byte[] into a Java object of the specified type.
      Parameters:
      type - the Type object of the desired type
      data - the byte[] containing the JSON data
      Returns:
      the deserialized object
    • toJsonStream

      default <E> void toJsonStream(Iterator<E> iterator, OutputStream os)
      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.
      Parameters:
      iterator - the stream of objects to be serialized
      os - the output stream to write the JSON-Stream data to