Reputation: 61
Recently something has been bugging me surrounding how to customize a JSON Response. So, here's the problem that I'm facing...
This is the entity class.
@Table(name="business") public class Business { private String var1; private String var2; private String var3; private String var4; }
This is the response class that I will eventually return to the client.
public class businessResponse {
private Business business;
}
So, if I need only var1 and var2 returned, what should I do. I can @JsonIgnore
on the POJO, but I don't want to do that, as some other response might well need them. I have also tried @JsonIgnoreProperty({"var3","var4})
on the response class and it didn't work.
Can anyone suggest a solution to achieve this thing? I am new to Hibernate and Spring Boot, so a little help would really work.
Upvotes: 1
Views: 690
Reputation: 18480
You should use @JsonIgnoreProperties
instead of @JsonIgnoreProperty
on business
field in BusinessResponse
instead of BusinessResponse
class
public class BusinessResponse {
@JsonIgnoreProperties({"var3", "var4" })
private Business business;
}
Upvotes: 2