Skip to content

Instantly share code, notes, and snippets.

@horte
Created March 2, 2012 18:43
Show Gist options
  • Save horte/1960310 to your computer and use it in GitHub Desktop.
Save horte/1960310 to your computer and use it in GitHub Desktop.
Jackson ObjectMapper Configuration ignore all fields as default
//Turn off visibility for all fields when serializing (forces @JsonProperty annotations on entities)
setVisibilityChecker(getSerializationConfig().getDefaultVisibilityChecker()
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE)
.withFieldVisibility(JsonAutoDetect.Visibility.NONE)
.withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withSetterVisibility(JsonAutoDetect.Visibility.NONE));
//Turn off visibility for all fields when deserializing (forces @JsonProperty annotations on entities)
setVisibilityChecker(getDeserializationConfig().getDefaultVisibilityChecker()
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE)
.withFieldVisibility(JsonAutoDetect.Visibility.NONE)
.withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withSetterVisibility(JsonAutoDetect.Visibility.NONE));
//My annotated obj
public class SomeObj {
@JsonProperty
private Long id;
@JsonProperty
private String name;
private Date date;
private List<Integer> list;
@JsonProperty
private User user;
@JsonProperty
private MyObj myObj;
....
}
@enrichman
Copy link

@ashish-tyagi
Copy link

Thanks, it works for me. Sadly I can not upvote your answer, as I do not have enough reputation points yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment