Skip to content

Existing instance of a local/anonymous Class cannot be updated #3229

Description

@avshenuk

When using readerForUpdating with an existing object, Jackson fails with:

Cannot deserialize Class mypackage.MyClass$1 (of type local/anonymous) as a Bean
	at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.isPotentialBeanType(BeanDeserializerFactory.java:883)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:137)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:414)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:349)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:264)

Version information
2.10.3

To Reproduce

package mypackage;
public class MyClass {
   public static void main(int[] args) {
       Object resultObject = new Object() {
           int value;
       }
       new ObjectMapper().readerForUpdating(resultObject).readValue("{\"value\": 2}");
   }
}

Expected behavior
Since Jackson is not required to construct an instance of the anonymous class, it should be able to populate the fields on the existing object.
Investigation shows that the method

public Object deserialize(JsonParser p, DeserializationContext ctxt, Object bean) throws IOException

in com.fasterxml.jackson.databind.deser.BeanDeserializer doesn't use ValueInstantiator _valueInstantiator field.

So can it be made optional when you're updating an existing instance?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions