Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guava collection deserialization failure with Nulls.AS_EMPTY #67

Closed
ari-talja-rovio opened this issue Jul 3, 2020 · 4 comments
Closed
Milestone

Comments

@ari-talja-rovio
Copy link

Wrapped Guava collections don't deserialize properly anymore. This used to work in 2.9.10 but doesn't work in 2.10.4 anymore. For example the following code fails due to com.fasterxml.jackson.databind.exc.InvalidDefinitionException:

import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.Nulls;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.guava.GuavaModule;
import com.google.common.collect.ImmutableList;

public class JacksonTest {

    private static final ObjectMapper MAPPER = new ObjectMapper()
            .registerModule(new GuavaModule())
            .setDefaultSetterInfo(JsonSetter.Value.forContentNulls(Nulls.AS_EMPTY));

    public static void main(String[] args) throws Exception {
        String json = MAPPER.writeValueAsString(new TestClass());
        MAPPER.readValue(json, TestClass.class);
    }

    public static class TestClass {
        public ImmutableList<ImmutableList<String>> lists = ImmutableList.of();
    }
}

Setting defaultSetterInfo seems to pay a meaningful role in the bug, also it happens only with Guava collections. Normal List works fine.

As a result you get:

Exception in thread "main" com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot create empty instance of [collection type; class com.google.common.collect.ImmutableList, contains [simple type, class java.lang.String]], no default Creator
 at [Source: (String)"{"lists":[]}"; line: 1, column: 1]
	at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67)
	at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1592)
	at com.fasterxml.jackson.databind.deser.std.ContainerDeserializerBase.getEmptyValue(ContainerDeserializerBase.java:149)
	at com.fasterxml.jackson.databind.deser.std.StdDeserializer._findNullProvider(StdDeserializer.java:1167)
	at com.fasterxml.jackson.databind.deser.std.StdDeserializer.findContentNullProvider(StdDeserializer.java:1115)
	at com.fasterxml.jackson.datatype.guava.deser.GuavaCollectionDeserializer.createContextual(GuavaCollectionDeserializer.java:80)
	at com.fasterxml.jackson.databind.DeserializationContext.handlePrimaryContextualization(DeserializationContext.java:653)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:502)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:293)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
	at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
	at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:479)
	at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:4405)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4214)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3214)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3182)
	at JacksonTest.main(JacksonTest.java:18)

Full example code is available at https://github.com/ari-talja-rovio/jackson-example

@cowtowncoder
Copy link
Member

Yes, this sounds like regression of some kind, thank you for reporting it.
One thing you can try is to see if 2.11.1 works better. I will try to have a look at this issue in near future.

@ari-talja-rovio
Copy link
Author

I've tested it with 2.11.1 as well and it doesn't work on the newer versions either. Seems to be an issue with versions >= 2.10.0.

ImmutableList<List<T>> is fine but List<ImmutableList<T>> is not.

@cowtowncoder cowtowncoder changed the title Guava collection deserialization failure Guava collection deserialization failure with Nulls.AS_EMPTY Jul 4, 2020
@cowtowncoder
Copy link
Member

Thank you for reporting this, will check what is missing.

@cowtowncoder cowtowncoder added this to the 2.10.5 milestone Jul 4, 2020
@cowtowncoder
Copy link
Member

Fixed for 2.10.5, 2.11.2 (and 2.12.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants