Reputation: 181
I use the below libs
My @Entity
public class Products extends PanacheEntityBase implements Serializable{
private static final long serialVersionUID = 2L;
@Id
@Column( name = "id" )
public String id;
public String name;
public String description;
}
My Resources
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Products> getProducts() {
return Products.listAll() ;
}
With "quarkus-resteasy-jackson" I get
[{"id":"0b3d7518","name":"tests org","description":null},{"id":"78787518f","name":"ci tests org 2","description":"some text"}]
vs
With "quarkus-resteasy-jsonb" I get
[{"id":"0b3d7518f3","name":"tests org"},{"description":"some text","id":"78787518f","name":"ci tests org 2"}]
Question ?
If I use, quarkus-resteasy-jackson, it returns null value as a part of response. while quarkus-resteasy-jsonb does not return columns with null value as a part of response. "description" is not there in the response for id:0b3d7518f3. I need all fields. How can I achieve it. ?
Jackson order of json nodes is "id, name, description" the way I ordered in Entity. While JsonB it is "description,id,name". It is using sorted keys. Is there a way to override it in json?
Thanks
Upvotes: 2
Views: 4368
Reputation: 181
@Guillaume Smet above answer did help me solve it. Here is the code in case others are looking to..
@Singleton
public class MyJsonbFormatConfig implements JsonbConfigCustomizer {
public void customize(JsonbConfig config) {
config.withNullValues(true);
}
}
For ordering, here is the JsonbConfig property.
config.withPropertyOrderStrategy(PropertyOrderStrategy.LEXICOGRAPHICAL);
Upvotes: 2
Reputation: 10539
Well, I would say you answered the question yourself: if Jackson fits your needs, just use Jackson.
If you really want to use JSON-B, you can configure JsonbConfig
with a JsonbConfigCustomizer
bean.
See https://quarkus.io/guides/rest-json#json-b .
You can require the null values for sure and also tweak the ordering.
Upvotes: 2