Interface Jsonb


public interface Jsonb
Provides access to json adapters by type.


   Jsonb jsonb = Jsonb.newBuilder().build();

   JsonType<Customer> customerType = jsonb.type(Customer.class);

   Customer customer = ...;

   // write json
   String asJson = customerType.toJson(customer);

   // read json
   Customer customer = customerType.fromJson(asJson);

 
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Function to build a JsonAdapter that needs Jsonb.
    static interface 
    Build the Jsonb instance adding JsonAdapter, Factory or AdapterBuilder.
    static interface 
    Components register JsonAdapters Jsonb.Builder
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> JsonAdapter<T>
    adapter(Class<T> cls)
    Return the JsonAdapter used to read and write json for the given class.
    <T> JsonAdapter<T>
    adapter(Type type)
    Return the JsonAdapter used to read and write json for the given type.
    Create and return a new Jsonb.Builder to configure before building the Jsonb instance.
    properties(String... names)
    Return the property names as PropertyNames.
    reader(byte[] jsonBytes)
    Return the JsonReader used to read the given json content in bytes.
    reader(InputStream inputStream)
    Return the JsonReader used to read the json content from the given inputStream.
    reader(Reader reader)
    Return the JsonReader used to read the json content from the given reader.
    reader(String json)
    Return the JsonReader used to read the given json content.
    <T> JsonType<T>
    type(Class<T> cls)
    Return the JsonType used to read and write json for the given class.
    <T> JsonType<T>
    type(Type type)
    Return the JsonType used to read and write json for the given type.
    writer(OutputStream outputStream)
    Return the JsonWriter used to write json to the given outputStream.
    writer(Writer writer)
    Return the JsonWriter used to write json to the given writer.
  • Method Details

    • newBuilder

      Create and return a new Jsonb.Builder to configure before building the Jsonb instance.

      We can register JsonAdapter's to use for specific types before building and returning the Jsonb instance to use.

      Note that JsonAdapter's that are generated are automatically registered via service loading so there is no need to explicitly register those generated JsonAdapters.

    • type

      <T> JsonType<T> type(Class<T> cls)
      Return the JsonType used to read and write json for the given class.
    • type

      <T> JsonType<T> type(Type type)
      Return the JsonType used to read and write json for the given type.
    • adapter

      <T> JsonAdapter<T> adapter(Class<T> cls)
      Return the JsonAdapter used to read and write json for the given class.
    • adapter

      <T> JsonAdapter<T> adapter(Type type)
      Return the JsonAdapter used to read and write json for the given type.
    • reader

      Return the JsonReader used to read the given json content.
    • reader

      JsonReader reader(byte[] jsonBytes)
      Return the JsonReader used to read the given json content in bytes.
    • reader

      Return the JsonReader used to read the json content from the given reader.
    • reader

      Return the JsonReader used to read the json content from the given inputStream.
    • writer

      Return the JsonWriter used to write json to the given writer.
    • writer

      Return the JsonWriter used to write json to the given outputStream.
    • properties

      Return the property names as PropertyNames.

      Provides the option of optimising the writing of json for property names by having them already escaped and encoded rather than as plain strings.