When does Jackson lose interest in a custom deserializer or something like that?

385 views
Skip to first unread message

Benson Margulies

unread,
May 22, 2014, 10:22:15 AM5/22/14
to jackso...@googlegroups.com
I make a (haha) trivial change to some working code that has a custom deserializer for a class, and now I've got this. It looks like Jackson is trying to use 'construct+call setters' and getting sad instead of just calling my deserializer.

I'll probably track this down for myself, but just in case, here it is. I'll post the explanation if I derive it.

com.fasterxml.jackson.databind.JsonMappingException: Can not update object of type com.basistech.rosette.dm.ListAttribute (by deserializer of type com.basistech.rosette.dm.ListAttributeDeserializer) (through reference chain: com.basistech.rosette.dm.AnnotatedText["languageDetectionRegions"])
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:232)
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:197)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.wrapAndThrow(BeanDeserializerBase.java:1415)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:211)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:350)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1058)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:268)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:124)
at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1269)
at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:896)
at com.basistech.rosette.dm.JsonTest.roundTrip(JsonTest.java:152)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
Caused by: java.lang.UnsupportedOperationException: Can not update object of type com.basistech.rosette.dm.ListAttribute (by deserializer of type com.basistech.rosette.dm.ListAttributeDeserializer)
at com.fasterxml.jackson.databind.JsonDeserializer.deserialize(JsonDeserializer.java:128)
at com.fasterxml.jackson.databind.deser.impl.SetterlessProperty.deserializeAndSet(SetterlessProperty.java:117)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:209)
... 29 more

Pascal Gélinas

unread,
May 22, 2014, 10:35:44 AM5/22/14
to jackso...@googlegroups.com
Seems to me that you are using the mechanism for updating an existing value using ObjectReader#withValueToUpdate(Object), but your deserializer (ListAttributeDeserializer) doesn't implement the proper overload of the method deserialize for updating an object. You need to implement deserialize(JsonParser, DeserializationContext, T) or not use ObjectReader#withValueToUpdate(Object).

Hope this helps.
Pascal


--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
To post to this group, send email to jackso...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages