REST serialkization null values

93 views
Skip to first unread message

Tom Eicher

unread,
Jan 26, 2022, 9:10:50 AM1/26/22
to WildFly
Hello, I know this is not really a Wildfly problem, but, ...

after the upgrade to Wildfly 25 (from 10) REST messages will omit null values, e.g. for

@XmlAccessorType(XmlAccessType.FIELD)
public static class Facade {
        public String x = null;
}

@Produces({"application/json;charset=UTF-8"}) @Path("xxx")
public Response xxx() {
...
return Response.ok(new Facade()).build();
}

it used to return like
{ "x": null }

but now it returns like
{ }

I guess this is due to a newer RESTEasy version?

RESTEasy uses Jackson for JSON, right ?

So I would have to somehow/somewhere do a
mapper.setSerializationInclusion(Include.NON_NULL); ?

I tried various flavors of @NotNull, @JsonInclude(Include.ALWAYS),
@XmlElement(required = true) on the facade but nothing helped...

Any help appreciated!
Thx Cheers Tom.


Tom Eicher

unread,
Jan 26, 2022, 11:21:46 AM1/26/22
to WildFly
Alright so I tried out another two handful of annotations, and indeed

@JsonbNillable(true)

does the trick. (javax.json.bind.annotation)

Cheers Tom.

James Perkins

unread,
Jan 26, 2022, 11:30:37 AM1/26/22
to WildFly
Just as an FYI WildFly now defaults to using Jakarta JSON Binding for JSON serialization. You can use Jackson 2 instead, but that is no longer the default.

Tom Eicher

unread,
Jan 26, 2022, 11:41:51 AM1/26/22
to WildFly
...that would explain why @JsonIgnore did not help :-) 
Reply all
Reply to author
Forward
0 new messages