Skip to content

Commit 1b5308e

Browse files
committed
Add a failing test for #2725
1 parent 4f4f69d commit 1b5308e

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import com.fasterxml.jackson.annotation.JsonCreator;
7+
import com.fasterxml.jackson.annotation.JsonValue;
8+
import com.fasterxml.jackson.core.type.TypeReference;
9+
import com.fasterxml.jackson.databind.BaseMapTest;
10+
import com.fasterxml.jackson.databind.ObjectMapper;
11+
12+
public class EnumAsMapKey2725Test extends BaseMapTest
13+
{
14+
// [databind#2725]
15+
enum TestEnum2725 {
16+
FOO(1);
17+
18+
private final int i;
19+
20+
TestEnum2725(final int i) {
21+
this.i = i;
22+
}
23+
24+
@JsonValue
25+
public int getI() {
26+
return i;
27+
}
28+
29+
@JsonCreator
30+
public static TestEnum2725 getByIntegerId(final Integer id) {
31+
return id == FOO.i ? FOO : null;
32+
}
33+
34+
@JsonCreator
35+
public static TestEnum2725 getByStringId(final String id) {
36+
return Integer.parseInt(id) == FOO.i ? FOO : null;
37+
}
38+
}
39+
40+
private final ObjectMapper MAPPER = newJsonMapper();
41+
42+
// [databind#2725]
43+
public void testEnumAsMapKey2725() throws Exception
44+
{
45+
final Map<TestEnum2725, String> input = new HashMap<>();
46+
input.put(TestEnum2725.FOO, "Hello");
47+
48+
final String json = MAPPER.writeValueAsString(input);
49+
50+
final Map<TestEnum2725, String> output = MAPPER.readValue(json,
51+
new TypeReference<Map<TestEnum2725, String>>() { });
52+
53+
assertNotNull(output);
54+
assertEquals(1, output.size());
55+
}
56+
}

0 commit comments

Comments
 (0)