Closed hellboy81 closed 5 years ago
@hellboy81 try with
@Override
public void setupModule(SetupContext context) {
context.addSerializers(new Jdk8Serializers());
// Exception
context.addDeserializers(new Jdk8Deserializers());
// And to fully support Optionals, need to modify type info:
context.addTypeModifier(new Jdk8TypeModifier());
// Allow enabling "treat Optional.empty() like Java nulls"
if (_cfgHandleAbsentAsNull) {
context.addBeanSerializerModifier(new Jdk8BeanSerializerModifier());
}
}
329241 [INFO] org.codehaus.cargo.maven2.ContainerStartMojo - [talledLocalContainer] java.lang.VerifyError: Cannot inherit from final class
329241 [INFO] org.codehaus.cargo.maven2.ContainerStartMojo - [talledLocalContainer] at com.fasterxml.jackson.datatype.jdk8.Jdk8Module.setupModule(Jdk8Module.java:30)
329241 [INFO] org.codehaus.cargo.maven2.ContainerStartMojo - [talledLocalContainer] at com.fasterxml.jackson.databind.ObjectMapper.registerModule(ObjectMapper.java:550)
This is a custom class inheriting the jdk 8/jsr310 module?
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
mapper.registerModule(new com.fasterxml.jackson.datatype.jdk8.Jdk8Module());
TimeTestClass test = new TimeTestClass();
System.out.println(mapper.writeValueAsString(test));
This works fine - I think your container is trying to proxy the module class? Or you are extending the module class instead of copy and paste it. What cargo module are you running?
That certainly sounds like a version mismatch: that is, a dependency compiled against certain jackson-databind
version being included with different (usually older) minor version of jackson-databind
. Note that minor versions of different components SHOULD match, although most of the time they need to be partially ordered: that is, jackson-databind
2.7, for example, is ok with datatype modules 2.7.x, 2.8.x and 2.9.x -- but NOT the other way around.
Btw, this:
META-INF/lib/jackson-datatype-threetenbp-2.6.4.jar
looks suspicious: if it follows same versioning scheme, you should include 2.9.x version (or whatever is latest after 2.6). I think that as per:
https://mvnrepository.com/artifact/com.github.joschi.jackson/jackson-datatype-threetenbp
you should try 2.8.4
. This is not necessarily the problem but might be related.
I used jackson-datatype-jsr310 along with jackson-jaxrs-json-provider, version 2.10.3, and have the same issue. 😢
I tried several ways but was unable to resolve it.
e.g: add some other dependencies like jackson-core, jackson-databind. jackson-annotations
or exclude all transitive dependencies and declare them explicitly
But none works. One time, I tried to exclude the module com.fasterxml.jackson.core in jackson-jaxrs-json-provider the error is gone but I get another one and also unable to fix it:
Caused by: java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.ObjectReader.forType(Lcom/fasterxml/jackson/databind/JavaType;)Lcom/fasterxml/jackson/databind/ObjectReader; at com.fasterxml.jackson.jaxrs.base.ProviderBase.readFrom(ProviderBase.java:802) at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:634) at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:604)
@cowtowncoder any good idea that I can try to resolve this issue?
@huyle1097 You have a version incompatibility. You need to find which version(s) of Jackson jar(s) are out-of-date. Most likely jackson-databind
.
Thank you @cowtowncoder , I have several wars running on a Wildfly server in my scenario. And because my new war package uses a lib that contains the new Jackson version, whilst other legacy wars used the old one, it caused the issue.