Skip to content

Commit a6ed7f7

Browse files
committed
Clean up test for #47; have a look at how implement, realizing that it's... a pain to implement.
1 parent 5df4c4e commit a6ed7f7

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializers.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,19 @@ public static JsonSerializer<Object> getStdKeySerializer(JavaType keyType)
3030
if (cls == String.class) {
3131
return DEFAULT_STRING_SERIALIZER;
3232
}
33-
if (cls == Object.class) {
33+
if (cls == Object.class || cls.isPrimitive() || Number.class.isAssignableFrom(cls)) {
3434
return DEFAULT_KEY_SERIALIZER;
3535
}
36-
// [JACKSON-606] special handling for dates...
3736
if (Date.class.isAssignableFrom(cls)) {
3837
return (JsonSerializer<Object>) DateKeySerializer.instance;
3938
}
4039
if (Calendar.class.isAssignableFrom(cls)) {
4140
return (JsonSerializer<Object>) CalendarKeySerializer.instance;
4241
}
42+
/* 14-Mar-2014, tatu: Should support @JsonValue, as per #47; but that
43+
* requires extensive introspection, and passing in more information
44+
* to this method.
45+
*/
4346
// If no match, just use default one:
4447
return DEFAULT_KEY_SERIALIZER;
4548
}

src/test/java/com/fasterxml/jackson/failing/TestMapJsonValueKey.java

+11-16
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,40 @@
55

66
import com.fasterxml.jackson.annotation.JsonCreator;
77
import com.fasterxml.jackson.annotation.JsonValue;
8-
import com.fasterxml.jackson.core.type.TypeReference;
8+
import com.fasterxml.jackson.databind.BaseMapTest;
99
import com.fasterxml.jackson.databind.ObjectMapper;
10-
import com.fasterxml.jackson.test.BaseTest;
1110

12-
public class TestMapJsonValueKey extends BaseTest
11+
// [Issue#47]
12+
public class TestMapJsonValueKey extends BaseMapTest
1313
{
1414
public static class Wat
1515
{
1616
private final String wat;
1717

1818
@JsonCreator
19-
Wat(String wat)
20-
{
19+
Wat(String wat) {
2120
this.wat = wat;
2221
}
2322

2423
@JsonValue
25-
public String getWat()
26-
{
24+
public String getWat() {
2725
return wat;
2826
}
2927

3028
@Override
31-
public String toString()
32-
{
33-
return "[Wat: " + wat + "]";
29+
public String toString() {
30+
return "(String)[Wat: " + wat + "]";
3431
}
3532
}
3633

3734
public void testMapJsonValueKey()
3835
throws Exception
3936
{
40-
Map<Wat, Boolean> map = new HashMap<Wat, Boolean>();
41-
map.put(new Wat("3"), true);
42-
map.put(new Wat("x"), false);
43-
44-
TypeReference<Map<Wat, Boolean>> type = new TypeReference<Map<Wat, Boolean>>(){};
37+
Map<Wat, Boolean> input = new HashMap<Wat, Boolean>();
38+
input.put(new Wat("3"), true);
4539

4640
ObjectMapper mapper = new ObjectMapper();
47-
assertEquals(map, mapper.readValue(mapper.writeValueAsBytes(map), type));
41+
String json = mapper.writeValueAsString(input);
42+
assertEquals(aposToQuotes("{'3':'true'}"), json);
4843
}
4944
}

0 commit comments

Comments
 (0)