Reputation: 5654
I'm using JSON for my RESTful services and I have JSON (as the payload carrier format).
I'm using @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "class")
on interface IntA
. Class SuperClass
implements IntA
. MyClass
extends SuperClass
The problem I have is little weird. When I serialize and deserialize my classes using standalone main program, it works perfectly fine. However, when I deploy it over tomcat in a war and I try to deserialize, it says no such class found
Stacktrace:
Caused by: java.lang.IllegalArgumentException: Invalid type id 'com.abc.xyz.MyClass' (for id type 'Id.class'): no such class found
at org.codehaus.jackson.map.jsontype.impl.ClassNameIdResolver.typeFromId(ClassNameIdResolver.java:55)
at org.codehaus.jackson.map.jsontype.impl.TypeDeserializerBase._findDeserializer(TypeDeserializerBase.java:77)
at org.codehaus.jackson.map.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:67)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeWithType(BeanDeserializer.java:423)
at org.codehaus.jackson.map.deser.StdDeserializerProvider$WrappedDeserializer.deserialize(StdDeserializerProvider.java:460)
at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2376)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1166)
at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:410)
at org.apache.cxf.jaxrs.client.AbstractClient.readBody(AbstractClient.java:447)
Any help is greatly appreciated.
Upvotes: 5
Views: 6399
Reputation: 61993
How I solved this problem in my case (which may be completely unrelated to your case):
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader( classLoader );
try
{
invokeCodeThatPerformsSerializationDeserialization();
}
finally
{
Thread.currentThread().setContextClassLoader( oldClassLoader );
}
Upvotes: 1
Reputation: 116522
This sounds like a classpath issue: that is, Jackson code can not find named class with its classloader. If possible, maybe you could see where jars for Jackson and value class come from, and see if that would explain it. Classpath issues are quite notorious on servlet container deployments unfortunately.
Upvotes: 7