Package io.avaje.jsonb
Interface JsonType<T>
- All Superinterfaces:
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 TypeMethodDescriptionfromJson(byte[] content) Read the return the value from the json content.fromJson(JsonReader reader) Read the return the value from the reader.fromJson(InputStream inputStream) Read the return the value from the inputStream.Read the return the value from the reader.Read the return the value from the json content.fromObject(Object value) Convert from 'object form' expectingMap<String,Object>for 'json object' and expectingCollection<?>for 'json array'.list()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.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 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
Read the return the value from the json content. -
fromJson
Read the return the value from the json content. -
fromJson
Read the return the value from the reader. -
fromJson
Read the return the value from the inputStream. -
fromObject
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'.
-