-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Implement new SerializationFeature.IGNORE_FAILURE_TO_ORDER_MAP_ENTRIES_BY_INCOMPARABLE_KEYS
#4778
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
420ae68
feature : Add implementation for SerializationFeature.IGNORE_FAILURE_…
JooHyukKim 1faca12
chore : Clean up docs and naming etc...
JooHyukKim 5f3c1d1
Change feature name to `FAIL_ON_ORDER_MAP_BY_INCOMPARABLE_KEY`
JooHyukKim 7b8aa71
Implement eager comparable type check as suggested and also catch error
JooHyukKim a5017e6
Fix error failure
JooHyukKim 2d1e5f4
Apply review
JooHyukKim 7b95e2d
Doc modify java doc some more
JooHyukKim 6ff6bab
Update release notes
cowtowncoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.fasterxml.jackson.databind.tofix; | ||
package com.fasterxml.jackson.databind.deser; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missed this one: this is serialization, not deserialization test. Will move. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ughh how did I miss that 😂 thank you! |
||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
|
@@ -8,11 +8,10 @@ | |
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException; | ||
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; | ||
import com.fasterxml.jackson.databind.testutil.failure.JacksonTestFailureExpected; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
// [databind#4773] Test to verify `SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS` behavior | ||
// when serializing `Map` instances with un-comparable keys. | ||
|
@@ -32,9 +31,8 @@ public static class ObjectContainer4773 { | |
.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true) | ||
.build(); | ||
|
||
@JacksonTestFailureExpected | ||
@Test | ||
void testSerializationWithIncomparableKeys() | ||
void testSerializationFailureWhenEnabledWithIncomparableKeys() | ||
throws Exception | ||
{ | ||
// Given | ||
|
@@ -44,11 +42,15 @@ void testSerializationWithIncomparableKeys() | |
|
||
// When : Throws exception | ||
// com.fasterxml.jackson.databind.JsonMappingException: class java.util.Currency cannot be cast to class java.lang.Comparable | ||
String jsonResult = objectMapper.writeValueAsString(entity); | ||
|
||
// Then : Order should not matter, just plain old serialize | ||
assertTrue(jsonResult.contains("GBP")); | ||
assertTrue(jsonResult.contains("AUD")); | ||
try { | ||
objectMapper.writer() | ||
.with(SerializationFeature.FAIL_ON_ORDER_MAP_BY_INCOMPARABLE_KEY) | ||
.writeValueAsString(entity); | ||
fail("Should not pass"); | ||
} catch (InvalidDefinitionException e) { | ||
// Then | ||
verifyException(e, "Cannot order Map entries by key of incomparable type"); | ||
} | ||
} | ||
|
||
@Test | ||
|
@@ -75,4 +77,24 @@ void testSerializationWithGenericObjectKeys() | |
"'5':'N_TEXT'}}"), jsonResult); | ||
} | ||
|
||
@Test | ||
void testSerWithNullType() | ||
throws Exception | ||
{ | ||
// Given : Mixed keys with incomparable `Currency` and comparable `Integer` | ||
ObjectContainer4773 entity = new ObjectContainer4773(); | ||
entity.exampleMap.put(null, "AUD_TEXT"); | ||
|
||
// When : Throws exception | ||
try { | ||
objectMapper.writer() | ||
.with(SerializationFeature.FAIL_ON_ORDER_MAP_BY_INCOMPARABLE_KEY) | ||
.writeValueAsString(entity); | ||
fail("Should not pass"); | ||
} catch (InvalidDefinitionException e) { | ||
// Then | ||
verifyException(e, "Cannot order Map entries by key of incomparable type [null]"); | ||
} | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.