Skip to content

Instantly share code, notes, and snippets.

@rasheedamir
Forked from thurloat/example.java
Created March 18, 2016 10:41
Show Gist options
  • Save rasheedamir/4e5c3a6f94347f4a8e4f to your computer and use it in GitHub Desktop.
Save rasheedamir/4e5c3a6f94347f4a8e4f 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