Skip to content

Commit e20bcc8

Browse files
committed
Fix #1679
1 parent 4009fe3 commit e20bcc8

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

release-notes/VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Project: jackson-databind
1111
#1658: Infinite recursion when deserializing a class extending a Map,
1212
with a recursive value type
1313
(reported by Kevin G)
14+
#1679: `StackOverflowError` in Dynamic `StdKeySerializer`
1415

1516
2.8.9 (12-Jun-2017)
1617

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

+7
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType t
207207
protected JsonSerializer<Object> _findAndAddDynamic(PropertySerializerMap map,
208208
Class<?> type, SerializerProvider provider) throws JsonMappingException
209209
{
210+
// 27-Jun-2017, tatu: [databind#1679] Need to avoid StackOverflowError...
211+
if (type == Object.class) {
212+
// basically just need to call `toString()`, easiest way:
213+
JsonSerializer<Object> ser = new Default(Default.TYPE_TO_STRING, type);
214+
_dynamicSerializers = map.newWith(type, ser);
215+
return ser;
216+
}
210217
PropertySerializerMap.SerializerAndMapResult result =
211218
// null -> for now we won't keep ref or pass BeanProperty; could change
212219
map.findAndAddKeySerializer(type, provider, null);

src/test/java/com/fasterxml/jackson/failing/KeySerializers1679Test.java renamed to src/test/java/com/fasterxml/jackson/databind/ser/KeySerializers1679Test.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fasterxml.jackson.failing;
1+
package com.fasterxml.jackson.databind.ser;
22

33
import java.util.*;
44

@@ -18,8 +18,8 @@ public class KeySerializers1679Test extends BaseMapTest
1818
public void testRecursion1679() throws Exception
1919
{
2020
Map<Object, Object> objectMap = new HashMap<Object, Object>();
21-
objectMap.put(new Object(), new Object());
21+
objectMap.put(new Object(), "foo");
2222
String json = MAPPER.writeValueAsString(objectMap);
23-
assertEquals("{}", json);
23+
assertNotNull(json);
2424
}
2525
}

0 commit comments

Comments
 (0)