I use tomee to ignore the field in the json answer transient works for me, but I donβt know if it is the right way (there is no joson visible for my application, I just turned on jee -web api):
servlets
import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; @Path("/") @Produces({ MediaType.APPLICATION_JSON }) public class JsonApi { @GET @Path("testapi") public MyObject testApi() { return new MyObject("myname", "mycolor"); } }
An object
public class MyObject { public MyObject() { } public MyObject(String name, String color) { this.name = name; this.color = color; } public String name; public transient String color; }
Answer
{"name":"myname"}
source share