-
-
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.
Add bit more testing, related to investigation of #2101 (although ult…
…imately determined there is no bug)
- Loading branch information
1 parent
6abb1dd
commit 5256bfc
Showing
2 changed files
with
128 additions
and
25 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
65 changes: 65 additions & 0 deletions
65
src/test/java/com/fasterxml/jackson/failing/EnumAsIndexMapKey1877Test.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,65 @@ | ||
package com.fasterxml.jackson.failing; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.exc.InvalidFormatException; | ||
|
||
public class EnumAsIndexMapKey1877Test extends BaseMapTest | ||
{ | ||
public enum Type { | ||
ANY, | ||
OTHER | ||
} | ||
|
||
static class Container { | ||
private Type simpleType; | ||
private Map<Type, String> map; | ||
|
||
public Type getSimpleType() { | ||
return simpleType; | ||
} | ||
|
||
public void setSimpleType(Type simpleType) { | ||
this.simpleType= simpleType; | ||
} | ||
|
||
public Map<Type, String> getMap() { | ||
return map; | ||
} | ||
|
||
public void setMap(Map<Type, String> map) { | ||
this.map = map; | ||
} | ||
} | ||
// [databind#1877] | ||
public void testEnumAsIndexMapKey() throws Exception | ||
{ | ||
ObjectMapper mapper = newObjectMapper(); | ||
|
||
Map<Type, String> map = new HashMap<>(); | ||
map.put(Type.OTHER, "hello world"); | ||
Container container = new Container(); | ||
container.setSimpleType(Type.ANY); | ||
container.setMap(map); | ||
|
||
String json = mapper | ||
.writer().with(SerializationFeature.WRITE_ENUMS_USING_INDEX) | ||
.writeValueAsString(container); | ||
|
||
Container cont; | ||
try { | ||
cont = mapper | ||
.readerFor(Container.class) | ||
.readValue(json); | ||
} catch (JsonMappingException e) { | ||
throw e; | ||
} | ||
assertNotNull(cont); | ||
assertEquals(1, container.getMap().size()); | ||
InvalidFormatException foo = null; | ||
|
||
assertSame(Type.OTHER, container.getMap().keySet().iterator().next()); | ||
} | ||
} |