Created
March 2, 2012 18:43
-
-
Save horte/1960310 to your computer and use it in GitHub Desktop.
Jackson ObjectMapper Configuration ignore all fields as default
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
.... | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, it works for me. Sadly I can not upvote your answer, as I do not have enough reputation points yet.