Interface JSONDriver


public interface JSONDriver
Describes a JSON driver for Small.

In order to return Objects from Content-annotated, EntryPath-annotated methods, a class that implements this class needs to be in the component search.

Only one component needs to have this role. This is used for conversion if the output content MIME-type is application/json or no MIME-type is specified.

Author:
Matthew Tropiano
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    fromJSON(Reader reader, Class<T> type)
    Called when an object needs to be converted to an object from JSON.
    default <T> T
    fromJSONString(String json, Class<T> type)
    Converts an object to a JSON string from an object.
    void
    toJSON(Writer writer, Object object)
    Called when an object needs to be converted to JSON from an object.
    default String
    Converts an object to a JSON string from an object.
  • Method Details

    • fromJSON

      <T> T fromJSON(Reader reader, Class<T> type) throws IOException
      Called when an object needs to be converted to an object from JSON.
      Type Parameters:
      T - the return type.
      Parameters:
      reader - the provided reader to read JSON from.
      type - the target object type.
      Returns:
      the converted object.
      Throws:
      IOException - if an error occurs during the read.
    • toJSON

      void toJSON(Writer writer, Object object) throws IOException
      Called when an object needs to be converted to JSON from an object.
      Parameters:
      writer - the writer to write to.
      object - the object to convert and write.
      Throws:
      IOException - if an error occurs during the write.
    • fromJSONString

      default <T> T fromJSONString(String json, Class<T> type) throws IOException
      Converts an object to a JSON string from an object.
      Type Parameters:
      T - the type result.
      Parameters:
      json - the input JSON string.
      type - the type to convert to.
      Returns:
      the resultant JSON string.
      Throws:
      IOException - if an error occurs during the write.
    • toJSONString

      default String toJSONString(Object object) throws IOException
      Converts an object to a JSON string from an object.
      Parameters:
      object - the object to convert and write.
      Returns:
      the resultant JSON string.
      Throws:
      IOException - if an error occurs during the write.