JSON Binding (JSON-B) is a standard binding layer for converting Java objects to or from JSON messages. Oracle WebLogic Server 22.214.171.124.0 supports the Java API for JSON Binding 1.0 (JSR 367) specification by including the JSR-367 reference implementation for use with applications deployed on a WebLogic Server instance.
JSON-B defines a default mapping algorithm for converting existing Java classes to JSON, while enabling developers to customize the mapping process through the use of Java annotations. For more information, see:
This chapter includes the following sections:
About Default Mapping
Default mapping is a set of rules used by the JSON-B engine by default without any customization annotations and custom configuration provided.
This mapping is used for serializing and deserializing basic Java types (such as
java.lang.Boolean), Java SE types (such as
java.util.Optional), and Java date and time classes.
The main entry point in JSON-B is the
Jsonb class. It provides a set of overloaded
fromJson methods to serialize Java objects to JSON documents and deserialize them back.
Jsonb instances are thread safe and can be reused. It is recommended to have a single instance per configuration type.
You can map an object, a collection, or a generic collection:
Mapping an object
To map an object, you must first create a
Jsonbinstance, and use the
toJsonmethod to serialize to JSON and the
fromJsonmethod to deserialize back to an object.
Mapping a collection or a generic collection
JSON-B supports collections and generic collections handling. For proper deserialization, the runtime type of the resulting object needs to be passed to JSON-B during deserialization.
For more information about default mapping, see:
About Customized Mapping
You can customize your mapping in many ways. Use JSON-B annotations for compile time customizations and
JsonbConfig class for runtime customizations.
JSON-B supports the following customizations:
- Creating custom configurations with formatted output
- Changing property names
- Customizing the order of serialized properties
- Ignoring properties
- Changing the default null handling
- Using custom instantiation
- Changing the date and number formats
- Using binary encoding
- Using adapters
- Using serializer and deserializer classes
- Using strict I-JSON support
For more information about customized mapping, see:
Standard Support to Handle Application or JSON Media Type for JAX-RS
In a product that supports the Java API for JSON-B, implementations must support entity providers for all Java types supported by JSON-B in combination with the media types -
text/json, and any other media types matching
Note:If both JSON-B and JSON-P are supported in the same environment, entity providers for JSON-B take precedence over those for JSON-P, for all types except
JsonValueand its sub-types. Note the precedence with JSON-P.
If you selected to install the WebLogic Server Examples, you'll find an example that demonstrates how to use the Java API for JSON Binding with JAX-RS in the
ORACLE_HOME\wlserver\samples\server\examples\src\examples\javaee8\jsonb\jaxrs directory of your WebLogic Server distribution, where
ORACLE_HOME represents the directory in which you installed WebLogic Server. For more information about the WebLogic Server code examples, see Sample Applications and Code Examples in Understanding Oracle WebLogic Server.