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

Set.of() (Java 9) cannot be deserialized with polymorphic handling #3344

Closed
Sam-Kruglov opened this issue Dec 7, 2021 · 2 comments
Closed
Milestone

Comments

@Sam-Kruglov
Copy link

Sam-Kruglov commented Dec 7, 2021

Hi, 2.13.0 doesn't seem to work with Set.of() and I don't see any tests for it, there're only for List.of() and Map.of().

Originally posted by @Sam-Kruglov in #2900 (comment)

public static void main(String[] args) throws Exception {
    ObjectMapper mapper = JsonMapper.builder()
            .findAndAddModules()
            .activateDefaultTyping(LaissezFaireSubTypeValidator.instance, EVERYTHING, JsonTypeInfo.As.PROPERTY)
            .build();
    Set<?> set = Set.of("a", "b", "c");
    String actualJson = mapper.writeValueAsString(set);
    Set<?> output = mapper.readValue(actualJson, Set.class);
}

Output:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `java.util.ImmutableCollections$SetN` (no Creators, like default constructor, exist): no default no-arguments constructor found

Same example with List.of() works and is already here:

list = List.of("a", "b", "c");
actualJson = MAPPER.writeValueAsString(list);
output = MAPPER.readValue(actualJson, List.class);
assertEquals(3, output.size());

@cowtowncoder cowtowncoder changed the title Set.of() cannot be deserialized Set.of() cannot be deserialized with polymorphic handling Dec 8, 2021
@cowtowncoder
Copy link
Member

Since tests are under failing, likely those won't work on later JDKs either. But definitely worth adding a test for Set as well.

@Sam-Kruglov
Copy link
Author

I can confirm that I was running this example on JDK 11 on 2.13.0 and List.of() works fine

@cowtowncoder cowtowncoder changed the title Set.of() cannot be deserialized with polymorphic handling Set.of() 9cannot be deserialized with polymorphic handling Dec 27, 2021
@cowtowncoder cowtowncoder changed the title Set.of() 9cannot be deserialized with polymorphic handling Set.of() (Java 9) cannot be deserialized with polymorphic handling Dec 27, 2021
@cowtowncoder cowtowncoder added this to the 2.13.2 milestone Dec 27, 2021
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