I have 2 set of rest APIs implemented using Spring boot using same Java POJO class. I have to return different fields and with different name for few fields, based on API. Presently I am using @JsonView for one set of API. But I also need to give different name for that @JsonView. Ex: Field 'host' needs to be named as 'ip' for a @JsonView, where as 'host' for other API. I am not sure how to map different property names as per @JsonView.
I checked some results like using MixIns. But not sure how to do in Spring Boot Rest APIs, especially at method level.
public class Con {
@JsonView(View.ConInfo.class)
private String host;
private String name;
}
Controller Method:
@JsonView(View.ConInfo.class)
@GetMapping
public Con getConInfo() {}
@GetMapping("/raw")
public Con getCon() {}
Expected: {"ip":"10xxx"} for getConInfo API
{"host":"10xxx", "name":"con1"} for getCon API.
Actual: Getting {"host":"10xxx"} for getConInfo API