Skip to content

Instantly share code, notes, and snippets.

@thurloat
Created April 27, 2012 17:08
Show Gist options
  • Save thurloat/2510887 to your computer and use it in GitHub Desktop.
Save thurloat/2510887 to your computer and use it in GitHub Desktop.
Jackson JSON ignore on deserialize only
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;
}
}
@selalerercapitolis
Copy link

👍

@TheRealAbhinav
Copy link

👍

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