Skip to content

Instantly share code, notes, and snippets.

@syedbilalali
Forked from thurloat/example.java
Created September 10, 2019 12:22
Show Gist options
  • Save syedbilalali/7ca42f0fecc47c1105660b308386fe41 to your computer and use it in GitHub Desktop.
Save syedbilalali/7ca42f0fecc47c1105660b308386fe41 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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment