My application has two modules: an API A and a visualization component V.
Some API model classes are annotated via org.codehaus.jackson.annotation
(Jackson 1.9.13). In one logic flow, objects based on these models are JSON-serialized and delivered to V.
V currently uses com.fasterxml.jackson.core.ObjectMapper
(Jackson 2.9.1) for deserializing the received objects. (V does have A as a dependency, and hence Jackson 1.9.13 is also present in the classpath transitively.)
Since Jackson 2.9.1 is trying to deserialize the data into Jackson 1.9.13 annotated classes, some features like custom enum name mappings are not working. For example:
enum Size {
XL("Extra Large"),
L("Large"),
M("Medium"),
S("Small"),
XS("Extra Small");
private String name;
Size(String name) {
this.name = name;
}
public String getName() {
return name;
}
@org.codehaus.jackson.annotate.JsonCreator
public static Size forValue(String value) {
for (Size size : Size.values()) {
if (size.getName().equals(value)) {
return size;
}
}
return null;
}
}
class Model {
String name;
Size size;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSize() {
return size.getName();
}
public void setSize(Size size) {
this.size = size;
}
}
V fails to deserialize objects from the above Model
class, with this error:
com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `Size` from String "Medium": value not one of declared Enum instance names: [S, XL, M, XS, L]
at [Source: (String)"{"name":"foo","size":"Medium"}"; line: 1, column: 22] (through reference chain: Model["size"])
It all makes sense (since 1.9.13 to 2.9.1 is a backward-incompatible change), but what are my options? Will I have to downgrade V's deserialization logic to Jackson 1.9.13? Or, is there any "adaptor" or configuration that I could just "plug in" in order to get the 1.9.13 annotations working under 2.9.1?
(I'd rather not upgrade A to 2.9.1 at this point, because A's overall package size is a major concern; switching to com.fasterxml.jackson.core:jackson-databind
will grow A's overall Jackson dependency size from 980 KB to 1.51 MB - unacceptable because the complete core bundle (that builds upon A; does not include V) is currently well under 8 MB in size.)