0

I'm using the Gson Library and JAX-rs for a RestFull-API project. This is my endpoint:

@POST
@PermitAll
@Path("/search")
public List<Model> listAll(@BeanParam @Valid PageRequest page, SearchModelRequest request) {
    List<Model> models = modelDao.getOrderedByViews(page);
    return models;
}

The system automatically serialise the model object with a full JSON with all attributes, but I just want to send some of them; how Can I do?

I love coding
  • 1,183
  • 3
  • 18
  • 47

1 Answers1

0

By default in Gson if you mark the field as transient, it won't be considered in parsing.

e.g.:

private transient String name = "";

Nevertheless there are more ways to do it as explained in documentation:

https://sites.google.com/site/gson/gson-user-guide#TOC-Excluding-Fields-From-Serialization-and-Deserialization

  • Java Modifier Exclusion
  • Gson's @Expose
  • User Defined Exclusion Strategies
Pablo AM
  • 294
  • 1
  • 10