I am trying to deserialize JSON into a Java POJO using Jackson. The Json looks like
"foo": {
"one": {
"a":1,
"b":"string"
}
"three":{
"a":2
"b":"another"
}
...
}
And the class I want to deserialize into has this field:
public class Myclass {
private Map<MyEnum, MyPojo> foo;
//setter and getter
public static MyPojo {
private int a;
private String b;
}
}
And my enum type looks like this:
public enum MyEnum {
one("data1"),two("data2")
@JsonValue
String data;
EnumAttrib(String data) {
this.data = data;
}
private static Map<String, MyEnum> ENUM_MAP = new HashMap();
static {
for (MyEnum a: MyEnum.values()) {
ENUM_MAP.put(a.data, a);
}
}
@JsonCreator
public static MyEnum fromData(String string) {
return ENUM_MAP.get(string);
}
}
This solution works well as long us the JSON has known keys which are captured by MyEnum. How can I skip certain JSON elements from serialization (in this example "three
"), if it's not defined in MyEnum