Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

JSON-B (Jakarta JSON Binding) is the standard API and mapping contract for converting Java objects to and from JSON; Eclipse Yasson is an implementation of that standard. In a standalone Java application, include the JSON-B API and a compatible provider such as Yasson. In a Jakarta EE server, the runtime may already supply them, so check its supported version before adding dependencies.

What JSON-B and Yasson do

JSON-B defines the Java API and rules for binding JSON data to Java types. Yasson is Eclipse’s implementation of those rules, not a competing name for the standard. The Eclipse project describes Yasson as an official reference implementation of JSON Binding. The specification covers common Java values, date/time types, optional values, generic types, and JSON-P types.

This distinction matters for setup: your code can use the JSON-B API while the runtime provider performs the conversion. A Jakarta EE container may provide the API and provider; a plain Java application generally needs both on its runtime classpath. Consult the Jakarta JSON-B specification and the Eclipse Yasson project for their respective roles and documentation.

Choose dependencies for your runtime

For a standalone Maven application, declare the JSON-B API and an implementation. The API project documents the coordinate jakarta.json.bind:jakarta.json.bind-api; its README example uses version 3.0.0, which is an example rather than a claim that it is the newest release. Yasson’s Maven Central metadata identifies org.eclipse:yasson:3.0.5 as a relocation POM and directs users to org.eclipse.yasson:yasson. Check the current provider version and its compatibility with your API before copying coordinates into a build.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<dependencies>
  <dependency>
    <groupId>jakarta.json.bind</groupId>
    <artifactId>jakarta.json.bind-api</artifactId>
    <version>3.0.0</version>
  </dependency>
  <dependency>
    <groupId>org.eclipse.yasson</groupId>
    <artifactId>yasson</artifactId>
    <version>CHECK_CURRENT_COMPATIBLE_VERSION</version>
  </dependency>
</dependencies>

Replace the API version and provider placeholder with versions verified for your application; the API version above mirrors the repository example only. If you deploy to a Jakarta EE server, first check what it already provides to avoid bundling conflicting or incompatible copies. The Maven Central metadata for the former Yasson coordinate explains the relocation.

Version selection is especially important when adopting newer specifications. Jakarta JSON Binding 3.1 was released on November 12, 2025. JSON-B 3.0 is associated with Jakarta EE 10 and lists Java SE 11 or higher as its minimum; that documented 3.0 baseline should not be assumed for 3.1 without checking the release and implementation requirements for your chosen stack. See the JSON-B 3.1 release page, the JSON-B 3.0 release page, and the JSON-B API repository.

Serialize and deserialize a Java object

Once both the API and a provider are available at runtime, create a Jsonb instance, pass an object to toJson, and use fromJson with the target class to read it back. This small example uses a conventional Java bean with a no-argument constructor and matching accessors:

import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;

public class User {
    private String name;
    private int age;

    public User() {}

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
    public int getAge() { return age; }
    public void setAge(int age) { this.age = age; }
}

User user = new User("Ava", 30);
Jsonb jsonb = JsonbBuilder.create();

String json = jsonb.toJson(user);
User copy = jsonb.fromJson(json, User.class);

The JSON representation has properties corresponding to the bean’s mapped properties, such as name and age. The exact textual formatting is not a stable contract to rely on unless you configure it; JSON consumers should treat JSON as structured data rather than compare arbitrary whitespace. The API repository demonstrates the same toJson and fromJson workflow.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When finished, close the Jsonb instance to release provider resources, particularly in longer-lived applications:

jsonb.close();

Customize property names and output

Default naming is convenient when the JSON schema follows Java’s bean-property names. If an external API requires a different key, use JSON-B annotations to decouple the Java property from its JSON name. For example, annotate the getter or field according to the mapping style used by your class:

import jakarta.json.bind.annotation.JsonbProperty;

public class User {
    @JsonbProperty("display_name")
    public String getName() { return name; }
    // Other members omitted
}

JSON-B also supports programmatic configuration. Yasson’s examples show enabling null-valued properties and formatted output with JsonbConfig:

import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import jakarta.json.bind.JsonbConfig;

JsonbConfig config = new JsonbConfig()
    .withNullValues(true)
    .withFormatting(true);
Jsonb jsonb = JsonbBuilder.create(config);

These options change output behavior: including nulls can be necessary for a particular schema but can also add keys consumers may not expect; formatting makes JSON easier to inspect but is not needed for data interchange. Choose settings to match the receiving contract. The Yasson documentation includes configuration examples, and the specification documents mapping and customization options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Handle collections and generic types

Deserializing a single object is straightforward because User.class identifies the target type. Generic containers need more care: Java type erasure can hide element type information when a parameterized type is used indirectly. JSON-B supports generic binding, but when the method call cannot infer the complete target type, provide a java.lang.reflect.Type describing it to the appropriate fromJson overload. This lets the provider distinguish, for example, a list of users from an untyped list of maps. Consult the specification’s generic binding rules rather than assuming a raw List.class preserves its element type.

Troubleshoot common setup and mapping problems

  • Provider not found: In a standalone app, confirm that a JSON-B implementation such as Yasson is on the runtime classpath, not only present as a compile-time API dependency. In a managed server, check whether the server provides JSON-B and follow its deployment guidance.
  • Version or namespace mismatch: Verify that the API, provider, and server support compatible JSON-B versions and use the expected Jakarta namespace. Do not combine artifacts based only on similar version numbers.
  • Unexpected or missing property: Compare the JSON key with the mapped Java property. Check bean accessors, visibility, and any @JsonbProperty annotation; an external naming convention may require an explicit mapping.
  • Generic elements lose their Java type: Avoid relying on a raw collection class when deserializing parameterized data. Supply a reflective Type that retains the element type.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.