Package io.avaje.jsonb
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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description TfromJson(byte[] content)Read the return the value from the json content.TfromJson(JsonReader reader)Read the return the value from the reader.TfromJson(InputStream inputStream)Read the return the value from the inputStream.TfromJson(Reader reader)Read the return the value from the reader.TfromJson(String content)Read the return the value from the json content.TfromObject(Object value)Convert from 'object form' expectingMap<String,Object>for 'json object' and expectingCollection<?>for 'json array'.JsonType<List<T>>list()Return the list type for this JsonType.JsonType<Map<String,T>>map()Return the map with this type as the value type and string keys.JsonType<Set<T>>set()Return the set type for this JsonType.JsonView<T>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, toJsonPretty
-
-
-
-
Method Detail
-
view
JsonView<T> view(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(JsonReader reader)
Read the return the value from the reader.
-
fromJson
T fromJson(InputStream inputStream)
Read the return the value from the inputStream.
-
fromObject
T fromObject(Object value)
Convert from 'object form' expectingMap<String,Object>for 'json object' and expectingCollection<?>for 'json array'.- Parameters:
value- The json value that will be converted into T.- Returns:
- The value converted from 'object form'.
-
-