How do I configure an ObjectMapper to map only properties annotated with JsonProperty? (does not have to be this particular annotation, but this seemed the most sensible)
I am looking for something that works like Gson's @Expose annotation and GsonBuilder().excludeFieldsWithoutExposeAnnotation().create() serializer Example.
class Foo {
public String secret;
@JsonProperty
public String biz;
}
class FooTest {
public static void main(String[] args) {
ObjectMapper m = new ObjectMapper();
// configure the mapper
Foo foo = new Foo();
foo.secret = "secret";
foo.biz = "bizzzz";
System.out.println(m.writeValueAsString(foo));
// I want {"biz": "bizzzz"}
m.readValue("{\"secret\": \"hack\", \"biz\": \"settable\"}", Foo.class);
// I want this to throw an exception like secret does not exist
}
}
Thanks, Ransom