Reputation: 543
I need to ignore some fields in response of Zalando Logbook
logging
For example, if I have a Java response class:
class MyResponse {
private String fieldOne;
private String fieldTwo;
private String fieldThree;
}
I want to have a LOGGED response json:
{
"fieldOne": "abcd",
"fieldThree": "dcba"
}
I've tried to use BodyFilters, but it's still not working. How can I solve it?
Upvotes: 0
Views: 512
Reputation: 7790
It depends what library do you use to serialize your class to JSON. If you use JSON-Jackson library you will need to add @JsonIgnore
annotation to the field(s) that you want to ignore. So your class should look like this:
class MyResponse {
private String fieldOne;
@JsonIgnore
private String fieldTwo;
private String fieldThree;
}
Read this article for more info: Jackson Ignore Properties on Marshalling. Also, there is an open source MgntUtils library that provides a JsonUtils
class that allows you very simply to serialize classes to JSON String and parse them from JSON String to class instance. This util is a thing wrapper over JSON-Jackson library and, for simple cases, saves you writing any configuration related to the Jackson lib. Here is the Javadoc for JsonUtils class. The MgntUtils library can be obtained as Maven artifact from Maven Central or from Github (including Javadoc and source code). This library is written and maintained by me
Upvotes: 1