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
0
votes
1 answer

Do I need getters on JSON binding with Yasson?

I'm trying to avoid getters and setters on my POJO but Jersey is using my getter methods to convert my POJO to JSON. I tried using Yasson but when I tried to remove my getters it just returns blank JSON. // the POJO import…
0
votes
1 answer

JSON-B serializes Map keys using toString and not with registered Adapter

I have a JAX-RS service that returns a Map and I have registered a public class ArtifactAdapter implements JsonbAdapter which a see hit when deserializing the in-parameter but not when serializing the return…
Nicklas Karlsson
  • 317
  • 1
  • 4
  • 12
0
votes
1 answer

jsonb 1.0 / eclipse yasson ignores private properties without bean accessor methods

According to what I assume is the official user guide, http://json-b.net/users-guide.html, the engine should serialize any properties it finds, with or without bean accessor methods (I realize the Dog example uses public fields, but see the Person…
absmiths
  • 1,144
  • 1
  • 12
  • 21
0
votes
1 answer

Force JSON-B to write Numbers as Strings when generating JSON

I'm dealing with large numbers in my Java code and because of the limitations of JavaScript (namely the 32-bit support of Integers), I need to write those numbers as Strings in the JSON returned by my application. Is there a global configuration or…
Fábio
  • 3,291
  • 5
  • 36
  • 49
0
votes
1 answer

JSON-B hitting NPE serializing with adapter though setting withNullValues(true)

Problem The JSON-B user guide suggests here that I should be able to serialize null values with my code of: Jsonb jsonb = JsonbBuilder.create(new JsonbConfig() .withNullValues(true) .withAdapters(new StatusAdapter())); …
Scott Kurz
  • 4,985
  • 1
  • 18
  • 40
0
votes
1 answer

JAX-RS 2.1: JSON-B adapter applied when unexpected

Problem: Given the REST endpoint: @Path("/companies") @Stateless public class CompanyService{ @EJB private CompanyEjb ejb; @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Company…
Al-un
  • 3,102
  • 2
  • 21
  • 40
0
votes
1 answer

jsonb: nested serializing not called by Jsonb

New Tag request: java-ee-8 It's got a new feature, called jsonb. With jsonb, I cannot get nested serialization working. See bold printed below. So, I wrote a jaxrs-application. This application's got a messagebodywriter using jsonb: final…
Benjamin Marwell
  • 1,173
  • 1
  • 13
  • 36
1 2 3
4