-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor tweaks to fix for #1983, update release notes
- Loading branch information
1 parent
e5d22e2
commit d354028
Showing
6 changed files
with
95 additions
and
52 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
68 changes: 68 additions & 0 deletions
68
...est/java/com/fasterxml/jackson/databind/jsontype/JsonTypeInfoCaseInsensitive1983Test.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.fasterxml.jackson.databind.jsontype; | ||
|
||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.exc.InvalidTypeIdException; | ||
|
||
// Tests wrt [databind#1983] | ||
public class JsonTypeInfoCaseInsensitive1983Test extends BaseMapTest | ||
{ | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, | ||
property = "Operation") | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = Equal.class, name = "eq"), | ||
@JsonSubTypes.Type(value = NotEqual.class, name = "notEq"), | ||
}) | ||
static abstract class Filter { | ||
} | ||
|
||
static class Equal extends Filter { } | ||
|
||
static class NotEqual extends Filter { } | ||
|
||
// verify failures when exact matching required: | ||
private final ObjectMapper MAPPER = newJsonMapper(); | ||
|
||
public void testReadMixedCaseSubclass() throws Exception | ||
{ | ||
final String serialised = "{\"Operation\":\"NoTeQ\"}"; | ||
|
||
// first: mismatch with value unless case-sensitivity disabled: | ||
try { | ||
MAPPER.readValue(serialised, Filter.class); | ||
fail("Should not pass"); | ||
} catch (InvalidTypeIdException e) { | ||
verifyException(e, "Could not resolve type id 'NoTeQ'"); | ||
} | ||
|
||
ObjectMapper mapper = jsonMapperBuilder() | ||
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_VALUES) | ||
.build(); | ||
// Type id ("value") mismatch, should work now: | ||
Filter result = mapper.readValue(serialised, Filter.class); | ||
|
||
assertEquals(NotEqual.class, result.getClass()); | ||
} | ||
|
||
public void testReadMixedCasePropertyName() throws Exception | ||
{ | ||
final String serialised = "{\"oPeRaTioN\":\"notEq\"}"; | ||
// first: mismatch with property name unless case-sensitivity disabled: | ||
try { | ||
MAPPER.readValue(serialised, Filter.class); | ||
fail("Should not pass"); | ||
} catch (InvalidTypeIdException e) { | ||
verifyException(e, "Missing type id when trying to resolve subtype"); | ||
} | ||
|
||
ObjectMapper mapper = jsonMapperBuilder() | ||
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES) | ||
.build(); | ||
// Type property name mismatch (but value match); should work: | ||
Filter result = mapper.readValue(serialised, Filter.class); | ||
|
||
assertEquals(NotEqual.class, result.getClass()); | ||
} | ||
} |
44 changes: 0 additions & 44 deletions
44
src/test/java/com/fasterxml/jackson/failing/JsonTypeInfoCaseInsensitive1983Test.java
This file was deleted.
Oops, something went wrong.