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 Detail

      • view

        JsonView<Tview​(String dsl)
        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))
        
         
      • 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.
      • fromObject

        T fromObject​(Object value)
        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'.