Package io.avaje.jsonb
Interface Jsonb
public interface Jsonb
Provides access to json adapters by type.
Initialise with defaults
Initialise with defaults
Jsonb jsonb = Jsonb.newBuilder().build();
Initialise with some configuration
Jsonb jsonb = Jsonb.newBuilder()
.serializeNulls(true)
.serializeEmpty(true)
.failOnUnknown(true)
.build();
fromJson
Jsonb jsonb = Jsonb.newBuilder().build();
Jsonb jsonb = Jsonb.newBuilder()
.serializeNulls(true)
.serializeEmpty(true)
.failOnUnknown(true)
.build();
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);
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceFunction to build a JsonAdapter that needs Jsonb.static interfaceBuild the Jsonb instance adding JsonAdapter, Factory or AdapterBuilder.static interfaceComponents register JsonAdapters Jsonb.Builder -
Method Summary
Modifier and TypeMethodDescription<T> JsonAdapter<T>Return the JsonAdapter used to read and write json for the given class.<T> JsonAdapter<T>Return the JsonAdapter used to read and write json for the given type.static Jsonb.BuilderCreate 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.Return the JsonReader used to read the json content from the given reader.Return the JsonReader used to read the given json content.<T> JsonType<T>Return the JsonType used to read and write json for the given class.<T> JsonType<T>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.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.
Jsonb jsonb = Jsonb.newBuilder() .serializeNulls(true) .serializeEmpty(true) .failOnUnknown(true) .build(); -
type
Return the JsonType used to read and write json for the given class. -
type
Return the JsonType used to read and write json for the given type. -
adapter
Return the JsonAdapter used to read and write json for the given class. -
adapter
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
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.
-