Jakarta JSON processing and binding compared with Jackson
Compare Jakarta JSON-P and JSON-B with Jackson using Java examples, then check provider integration, Kotlin constructors, and stable date formats.
JSON parsing and Java object binding are separate problems. Jakarta defines a standard API for each. I compare them with Jackson to see which layer a project depends on and what can change when a mapper is replaced.
The examples use Java 21, JSON-B 3.0 with Yasson 3.0.4, JSON-P 2.1 with Parsson 1.1.7, and Jackson 2.18.
Separating JSON processing from object binding
JSON-P indexes values in a JSON object model or exposes them as sequential parser events. Use the object model when you need random access to a small document. A parser can extract a few fields from a large input without building the complete value tree.
JSON-B maps Java types to and from JSON and uses provider configuration to control binding. Yasson implements JSON-B and uses a JSON-P provider underneath. Jackson makes a similar separation between its streaming core and databind module.
flowchart TD
App["Application Code"] -->|"Object binding"| JSONB["JSR-367: Jakarta JSON-B API"]
App -->|"Tree or streaming"| JSONP["JSR-374: Jakarta JSON-P API"]
JSONB -->|"SPI (JsonbProvider)"| Yasson["Eclipse Yasson (provider)"]
Yasson -->|"Delegate parsing and generation"| JSONP
JSONP -->|"SPI (JsonProvider)"| Parsson["Eclipse Parsson (provider)"]
Parsson -->|"Token / Byte Stream"| IO["JSON Stream (UTF-8)"]
Comparing the parsing and mapping examples
The dependencies pair each Jakarta API with an implementation. The JSON-P example works with JSON structures directly. The JSON-B and Jackson examples bind objects using their distinct entry points.
1
2
3
4
5
6
7
// build.gradle.kts
dependencies {
implementation("jakarta.json.bind:jakarta.json.bind-api:3.0.1")
runtimeOnly("org.eclipse:yasson:3.0.4")
implementation("jakarta.json:jakarta.json-api:2.1.3")
runtimeOnly("org.eclipse.parsson:parsson:1.1.7")
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// src/main/java/com/example/json/JsonpExample.java
package com.example.json;
import jakarta.json.Json;
import jakarta.json.JsonObject;
import jakarta.json.stream.JsonParser;
import java.io.StringReader;
public class JsonpExample {
public static void main(String[] args) {
JsonObject payload = Json.createObjectBuilder()
.add("orderId", "ORD-2026-001")
.add("amount", 45000)
.build();
try (JsonParser parser = Json.createParser(new StringReader(payload.toString()))) {
while (parser.hasNext()) {
JsonParser.Event event = parser.next();
if (event == JsonParser.Event.KEY_NAME && "amount".equals(parser.getString())) {
parser.next();
System.out.println("Parsed amount = " + parser.getInt());
}
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// src/main/java/com/example/json/JsonbExample.java
package com.example.json;
import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import jakarta.json.bind.JsonbConfig;
import jakarta.json.bind.annotation.JsonbDateFormat;
import jakarta.json.bind.annotation.JsonbProperty;
import jakarta.json.bind.annotation.JsonbTransient;
import java.time.LocalDateTime;
public class JsonbExample {
public record OrderDto(
@JsonbProperty("order_id") String orderId,
int amount,
@JsonbDateFormat("yyyy-MM-dd'T'HH:mm:ss") LocalDateTime createdAt,
@JsonbTransient String internalMemo
) {}
public static void main(String[] args) throws Exception {
JsonbConfig config = new JsonbConfig().withFormatting(true);
try (Jsonb jsonb = JsonbBuilder.create(config)) {
OrderDto order = new OrderDto("ORD-100", 32000, LocalDateTime.now(), "secret");
String json = jsonb.toJson(order);
OrderDto restored = jsonb.fromJson(json, OrderDto.class);
System.out.println("Restored = " + restored.orderId());
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// src/main/java/com/example/json/JacksonExample.java
package com.example.json;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import java.time.LocalDateTime;
public class JacksonExample {
public record OrderDto(
@JsonProperty("order_id") String orderId,
int amount,
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") LocalDateTime createdAt,
@JsonIgnore String internalMemo
) {}
public static void main(String[] args) throws Exception {
ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule());
OrderDto order = new OrderDto("ORD-100", 32000, LocalDateTime.now(), "secret");
String json = mapper.writeValueAsString(order);
OrderDto restored = mapper.readValue(json, OrderDto.class);
System.out.println("Restored = " + restored.orderId());
}
}
This separation matters when deployment changes the runtime. A hosted Jakarta application may already supply the expected providers. A standalone application needs compatible API and provider implementations on its runtime classpath.
Comparing the two binding APIs
| Concern | Jakarta JSON-B and JSON-P | Jackson |
|---|---|---|
| Binding entry point | Jsonb | ObjectMapper |
| Streaming | JSON-P parser | Jackson Core parser |
| Polymorphism | @JsonbTypeInfo in JSON-B 3.0 | @JsonTypeInfo and related metadata |
| Kotlin support | Check constructor and creator configuration | jackson-module-kotlin |
| Other wire formats | JSON | Modules for formats such as YAML, CBOR, and XML |
| Configuration | Binding adapters and serializers | Features, mix-ins, views, adapters, and serializers |
Boot 3 applications often use Jackson because the framework supplies and configures the mapper and because its modules match the rest of the application. Jakarta JSON-B is a reasonable fit when a Jakarta runtime supplies it and the available binding features match the contract.
Keeping binding behavior consistent
Reuse configured mapper instances where supported by their threading contracts. With Jsonb, close the instance during shutdown. Creating new mappers on every request adds work and may own resources the application must release.
A class with no default constructor needs a creation path understood by the binding provider. That can require a supported creator annotation, module, or adapter.
1
jakarta.json.bind.JsonbException: Can't create instance of a class: class com.example.Order, No default constructor found.
For public APIs, decide how to encode timestamps and local date-times. A manually constructed Jackson mapper does not inherit Boot’s modules and feature flags. Register Java time support and choose a stable date format. Test both directions with fixtures for constructors, absent fields, and dates. If the application uses polymorphic values, include representative subtypes and unknown type values.