Class JsonOutputConverter<T>

  • Type Parameters:
    T - the type of the object to convert to a JSON Object
    All Implemented Interfaces:
    OutputConverter<T>

    public class JsonOutputConverter<T>
    extends OutputStreamOutputConverter<T>
    implements OutputConverter<T>
    An OutputConverter that converts an object into a JSON Object that is written to an OutputStream. The actual conversion to JSON is handled by using an instance of JsonConverter.
    • Constructor Detail

      • JsonOutputConverter

        public JsonOutputConverter​(Class<T> targetClass)
        Construct a new instance of a JsonOutputConverter that is able to convert objects of the specified targetClass into JSON Objects and write them into the OutputStream.
        Parameters:
        targetClass - The class defining the objects being converted into JSON.
    • Method Detail

      • write

        public void write​(T t)
        Converts an object into a JSON Object that is written to the InputStream. If the specified targetClass in the constructor equals to JsonObject.class, then this method will cast the provided object into a JsonObject instance and write it directly to the OutputStream. Otherwise, a JsonConverter will be used to convert the object into a JSON Object.
        Specified by:
        write in interface OutputConverter<T>
        Parameters:
        t - The object to convert into a JSON Object that will be written to the OutputStream.