leandro.dev
leandro.dev

Reputation: 365

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

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?

Upvotes: 0

Views: 280

Answers (1)

Volodya Lombrozo
Volodya Lombrozo

Reputation: 3476

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
}

Upvotes: 0

Related Questions