How to send null values using jaxrs-jsonb (JSON-B | JSR-367)?

174 Views Asked by At

I am working in a legacy system with Java/EJB/JPA/thorntail/wildfly.

The project has:

      <dependency>
        <groupId>io.thorntail</groupId>
        <artifactId>jaxrs-jsonb</artifactId>
        <version>2.6.0.Final</version>
      </dependency>

JSON-B provides support for JSON Processing according to JSR-367.

I need to send null values in API/Rest. Anything similar to @JsonInclude(Include.ALWAYS) for Jackson.

Example that I need:

PersonApi with name=Any, age=null

{
    "name": "Any",
    "age": null
}

Is there some config to do this? ... some annotation, some config to load and resolve it?

1

There are 1 best solutions below

2
Volodya Lombrozo On

You can use javax.json.bind.annotation.JsonbNillable annotation:

@JsonbNillable
public static class PersonApi {
    private String name;
    private Integer age;
    //constructors, getters and setters are omitted
}