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

Class name handling for Collections.emptyMap() changed in 2.9.3+ #1881

Closed
rwinch opened this issue Jan 10, 2018 · 3 comments
Closed

Class name handling for Collections.emptyMap() changed in 2.9.3+ #1881

rwinch opened this issue Jan 10, 2018 · 3 comments

Comments

@rwinch
Copy link

rwinch commented Jan 10, 2018

Similar to #1868 the following test works in jackson-databind 2.9.2 and prior, but breaks in 2.9.3 and 2.9.4-SNAPSHOT

@Test
public void serializeEmptyMap() throws Exception {
	ObjectMapper mapper = new ObjectMapper();
	mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
	String actualJson = mapper.writeValueAsString(Collections.emptyMap());
	assertEquals("{\"@class\":\"java.util.Collections$EmptyMap\"}", actualJson);
}

with the following

org.junit.ComparisonFailure: 
Expected :{"@class":"java.util.Collections$EmptyMap"}
Actual   :{"@class":"java.util.HashMap"}
@cowtowncoder
Copy link
Member

Hmmh. Now this is also dangerous one. But, I do think that preserving existing behavior (and not trying for "unrequested fix" here), that is, 2.9.2, not modifying class name, is the least bad option.

With 3.x probably makes sense to somehow connect this to other "change the class name on the fly" functionality (white-listing). Or, if deemed worth it, custom deserializer for these types. Even if JDK does not offer real help in determining such add-on qualifiers (empty, singleton, unmodifiable).

@rwinch
Copy link
Author

rwinch commented Jan 10, 2018

I should add that this is also happening in 2.8.11.1-SNAPSHOT

@cowtowncoder
Copy link
Member

Fixed along with #1880 -- see notes on that one.

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