Created
April 27, 2012 17:08
-
-
Save thurloat/2510887 to your computer and use it in GitHub Desktop.
Jackson JSON ignore on deserialize only
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
package com.thurloat.foo; | |
import org.codehaus.jackson.annotate.JsonIgnore; | |
import org.codehaus.jackson.annotate.JsonProperty; | |
/** | |
* In order to write a composite data property (stats) out to JSON without reading | |
* it back in, you need to explicitly ignore the property, as well as the setter and | |
* then apply the @JsonProperty annotation to the getter. | |
**/ | |
public class Foo { | |
@JsonIgnore | |
private FooStats stats; | |
private String label; | |
@JsonProperty("stats") | |
public FooStats getFooStats() { | |
return stats; | |
} | |
@JsonIgnore | |
public void setFooStats(FooStats stats) { | |
this.stats = stats; | |
} | |
public String getLabel() { | |
return label; | |
} | |
public void setLabel(String label) { | |
this.label = label; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍