Interface JsonType<T>

All Superinterfaces:
JsonView<T>

public interface JsonType<T> extends JsonView<T>
Provides API to serialise a type to and from JSON.

JsonType provides the main API used to read and write json.

fromJson

Read json content from: String, byte[], Reader, InputStream, JsonReader



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

  Customer customer = customerType.fromJson(content);

 

toJson

Write json content to: String, byte[], Writer, OutputStream, JsonWriter



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

  String asJson = customerType.toJson(customer);

 

Moshi note: JsonType does not exist in Moshi and has been added to provide a slightly nicer API to use than JsonAdapter.

  • Method Summary

    Modifier and Type
    Method
    Description
    fromJson(byte[] content)
    Read the return the value from the json content.
    Read the return the value from the reader.
    fromJson(InputStream inputStream)
    Read the return the value from the inputStream.
    fromJson(Reader reader)
    Read the return the value from the reader.
    fromJson(String content)
    Read the return the value from the json content.
    Convert from 'object form' expecting Map<String,Object> for 'json object' and expecting Collection<?> for 'json array'.
    Return the list type for this JsonType.
    map()
    Return the map with this type as the value type and string keys.
    set()
    Return the set type for this JsonType.
    view(String dsl)
    Build and return the view given the DSL that specifies the properties to include.

    Methods inherited from interface io.avaje.jsonb.JsonView

    toJson, toJson, toJson, toJson, toJsonBytes
  • Method Details

    • view

      Build and return the view given the DSL that specifies the properties to include.

      Examples of json view DSL:

      
      
         // only include the id and name properties
         (id, name)
      
         // include billAddress which is a nested type
         (id, name, billingAddress(street, suburb))
      
         // include billAddress with all it's properties
         (id, name, billingAddress(*))
      
         (id, name, billingAddress(street, suburb), shippingAddress(*), contacts(email,lastName, firstName))
      
       
    • list

      Return the list type for this JsonType.
    • set

      Return the set type for this JsonType.
    • map

      Return the map with this type as the value type and string keys.
    • fromJson

      Read the return the value from the reader.
    • fromJson

      T fromJson(String content)
      Read the return the value from the json content.
    • fromJson

      T fromJson(byte[] content)
      Read the return the value from the json content.
    • fromJson

      T fromJson(Reader reader)
      Read the return the value from the reader.
    • fromJson

      T fromJson(InputStream inputStream)
      Read the return the value from the inputStream.
    • fromObject

      Convert from 'object form' expecting Map<String,Object> for 'json object' and expecting Collection<?> for 'json array'.
      Parameters:
      value - The json value that will be converted into T.
      Returns:
      The value converted from 'object form'.