Questions tagged [jsonb-api]

For questions about Java API for JSON Binding (JSON-B, JSR-367), part of Java EE 8.

From json-b.net:

JSON-B is a standard binding layer for converting Java objects to/from JSON messages. It 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.

To serialize/deserialize a Java Object to/from JSON

The Java Class

public class Dog {
    public String name;
    public int age;
    public boolean bitable;
}

JSON-B API calls

public static void main(String[] args) {

    // Create a dog instance
    Dog dog = new Main.Dog();
    dog.name = "Falco";
    dog.age = 4;
    dog.bitable = false;

    // Create Jsonb and serialize
    Jsonb jsonb = JsonbBuilder.create();
    String result = jsonb.toJson(dog);

    System.out.println(result);

    // Deserialize back
    dog = jsonb.fromJson("{\"name\":\"Falco\",\"age\":4,\"bitable\":false}", Dog.class);

}

The JSON representation

{
    "name": "Falco",
    "age": 3,
    "bitable": false
}
52 questions
1
vote
2 answers

How can i import javax.json.binding in android studio?

I add the following dependency in my build.gradle file compile 'javax.json.bind:javax.json.bind-api:1.0.0-M2' it throws the error like Error:Execution failed for task…
Mohanraj
  • 296
  • 2
  • 13
1
vote
1 answer

Missing bridge between JSON-B and JSON APIs?

I'm trying to implement a function that applies a JSON-PATCH (RFC 6902) to an object annotated with JSON-B. I've come to the following solution: /** * Applies a JSON patch to a JSON-B annotated object, and returns a resulting patched version of the…
Stéphane Appercel
  • 1,427
  • 2
  • 13
  • 21
0
votes
0 answers

JsonbDeserializer deserializes JSON array into class java.lang.String

After changing yasson version to 3.0.3 JsonbDeserializer started to allow deserializing JSON array into String by taking last value from array and ignoring the rest of the values. I've checked previous yasson versions and this problem started to…
0
votes
2 answers

How to let Java library users choose between JSON parsing frameworks?

I am developing a Java library that can be used to call a certain web API that is using JSON data format to pass information. Said library will only contain data classes according to the data structure defined by the API spec. Code required to call…
Franz Wimmer
  • 1,477
  • 3
  • 20
  • 38
0
votes
1 answer

How to configure Json-B in RestEasy Client?

I use the RestEasy client. In the processed json object there is a base64 encoded byte array. However, the Yasson library assumes an int-coded array in the unconfigured case. How I tell the JsonConfig the BinaryDataStrategy.BASE_64? I have tried…
Superhugo
  • 1
  • 1
0
votes
0 answers

Serialize Enum along with its fields with Jakarta Jsonb

I want to serialise an enum containing details of a web API error into JSON. The entire application is a REST API is being built with Jakarta's APIs. I am using Jakarta EE's Jsonb for serializing and deserializing to and from JSON. My enum is as…
0
votes
0 answers

Is there a Yasson/Json-B equivalent for com.fasterxml.jackson.annotation.JsonValue

my question is if there is a Yasson/Json-B equivalent for com.fasterxml.jackson.annotation.JsonValue From the documentation of JsonValue: Marker annotation that indicates that the value of annotated accessor (either field or "getter" method [a…
MedMahmoud
  • 117
  • 1
  • 2
  • 15
0
votes
2 answers

NoClassDefFoundError jakarta/json/bind/JsonbBuilder

I am having an error while trying to use Jsonb / JsonbBuilder in a JakartaEE maven project. Error StackTrace java.lang.RuntimeException: jakarta/json/bind/JsonbBuilder at…
Adrianxu
  • 21
  • 4
0
votes
1 answer

Use Java records with JSON-B + Jax-RS

My project uses JSON-B with JAX-RS. The framework I am using is Quarkus and use Java 11. I tried to upgrade to Java 16 and use Java Records. It seems that JSON-B and Records does not work nicely. I have tried @JsonbCreator. But this annotation only…
sudhir shakya
  • 827
  • 1
  • 9
  • 21
0
votes
1 answer

Extract specific element from JSON using JSON-B

With Jackson we can extract specific element from JSON string and map it to relevant class, like below: ObjectMapper mapper = new ObjectMapper(); JsonNode root = mapper.readTree(someJson); JsonNode responseNode = root.get("response"); MyResponse…
YevgenyL
  • 281
  • 3
  • 20
0
votes
2 answers

Checking json fields using json-b api

I am using json binding API to parse json string for application deployed on Liberty application server. Suppose I have json string as given below String message = "{ "color" : "Black", "type" : "BMW" }"; I want to iterate through json string and…
cooldev
  • 497
  • 1
  • 3
  • 17
0
votes
1 answer

@JsonbTypeAdapter is not used by Spring Boot

I am trying to use Json-B with Spring Boot version: 2.3.1 Json-b javax.json.bind javax.json.bind-api 1.0
Long HDi
  • 33
  • 1
  • 6
0
votes
1 answer

Quarkus REST client avoid JSON serialization of Null Fields

I need to send on a remote service an update request in order to update some fields. The remote service use a application/json content type, so I have implemented my rest client…
Stefano Castoldi
  • 193
  • 2
  • 10
0
votes
1 answer

Unrecognized field ... not marked as ignorable, EE8 / Jakarta EE

I'm using Wildfly 18 with Resteasy. By passing an unknown property on body of my JSON API, I get this: Unrecognized field "foo" (class xxx), not marked as ignorable I know this is a jackson provider issue, on past projects I solved with this…
Fabrizio Stellato
  • 1,727
  • 21
  • 52
0
votes
1 answer

How can I find out, if a Java type is convertible from/to JSON

JSON-B converts types like LocalDate to/from a simple String. When I have a Type, how can I find out if JSON-B will convert this type directly, i.e. if it's a scalar type? I don't have an instance, so I can't even just try to convert it to a String…
rü-
  • 2,129
  • 17
  • 37