0

Context: A Spring REST Web Service where is sends a response with POJO (example: Output.java) Now, Output.java contains 2 fields -

@JsonProperty("One")
private String one;
@JsonProperty("Two")
private String two;

So in the response I get both these field.

Question: How can I disable the field attribute "two" from coming in the response in my PROD environment ?

Melvins
  • 320
  • 2
  • 9
  • There is no any annotation or declaration that prevent properties from serialization on basis of environment. You can add `@JsonIgnore` annotation when you deployed your code to PROD. – Yagnesh Agola Sep 17 '15 at 06:59

2 Answers2

0

You can define custom JsonSerializer for the class and check whether it's PROD in the serializer and skip the field. See an example here

StanislavL
  • 56,971
  • 9
  • 68
  • 98
-1

Declare your Output.java with JsonSerialize.Inclusion.NON_NULL

@JsonSerialize(
include=JsonSerialize.Inclusion.NON_NULL)
public class Output {

}

If you don't populate property "two" in Output.java, then this property wont appear in your final rest response.

kswaughs
  • 2,967
  • 1
  • 17
  • 21