`StackOverflowError` in Dynamic `StdKeySerializer`
See original GitHub issueThere seem to be a problem (checked and doesn’t seem to be fixed in latest version) with the serialize method of the Dynamic static class of the StdKeySerializer.
@Override
public void serialize(Object value, JsonGenerator g, SerializerProvider provider)
throws IOException
{
Class<?> cls = value.getClass();
PropertySerializerMap m = _dynamicSerializers;
JsonSerializer<Object> ser = m.serializerFor(cls);
if (ser == null) {
ser = _findAndAddDynamic(m, cls, provider);
}
ser.serialize(value, g, provider);
}
The problem comes from the fact that when ser
is null
, the new ser
returned by _findAndAddDynamic
is incorrectly filled.
protected JsonSerializer<Object> _findAndAddDynamic(PropertySerializerMap map,
Class<?> type, SerializerProvider provider) throws JsonMappingException
{
PropertySerializerMap.SerializerAndMapResult result =
// null -> for now we won't keep ref or pass BeanProperty; could change
map.findAndAddKeySerializer(type, provider, null);
// did we get a new map of serializers? If so, start using it
if (map != result.map) {
_dynamicSerializers = result.map;
}
return result.serializer;
}
So say we are in ser#1
, ser#1._dynamicSerializers
now has the correct PropertySerializerMap$Single
. However, result.serializer._dynamicSerializers
has PropertySerializerMap$Empty
.
Therefore, a new call with that result ser#2
is made which ends up creating an infinite loop.
Possible fix:
- replace
_dynamicSerializers = result.map;
byresult.serializer._dynamicSerializers = result.map
If I’m mistaken please let me know, but It seems obvious when debugging that something’s is not working as intended
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
StackOverflowError in Dynamic StdKeySerializer #1679 - GitHub
There seem to be a problem (checked and doesn't seem to be fixed in latest version) with the serialize method of the Dynamic...
Read more >java.lang.StackOverflowError with jackson json and spring ...
The problem is that the event object itself references the session object. So if jackson reaches the session field in the event object...
Read more >StdKeySerializers.Dynamic (jackson-databind 2.9.0 API)
Method that can be called to ask implementation to serialize values of type this serializer handles. Methods inherited from class com.fasterxml.jackson.databind ...
Read more >com.fasterxml.jackson.databind.ser.std.StdKeySerializers ...
StdKeySerializers maven / gradle build tool code. The class is part of the package ➦ Group: com.fasterxml.jackson.core ➦ Artifact: jackson-databind ...
Read more >StackOverflowError in Java with examples - GeeksforGeeks
StackOverflowError is an error which Java doesn't allow to catch, for instance, stack running out of space, as it's one of the most...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@kpronovost I think I can figure out this case, but it probably does make sense to use a work-around in the meantime. But I think it’s good to fix this as the reproduction looks like something that would occur quite easily.
Thanks for the quick reply.
I already patched with realistic data in all test cases, I linked this issue to our Merge Request and will remove unneeded patch once this is resolved in a later version.
TLDR: Thanks for the fix; not a blocker.