StackOverflowError when serializing ObjectId with custom mapper

326 views
Skip to first unread message

Andreas Lundblad

unread,
Jun 19, 2014, 11:58:01 AM6/19/14
to mongo-jack...@googlegroups.com
Hi,

I'm trying to use MongoJack with my own custom ObjectMapper. I understand that I should call MongoJackModule.configure on my mapper to enable certain MongoJack features on the mapper. However, if I do this I get a StackOverflowError when trying serialize an ObjectId.

To clarify: The customization of my mapper includes code that performs the following during serialization of a certain object:

    jsonGenerator.writeObject(myEntity.getId());

where getId() returns an ObjectId. This causes a StackOverflowError that looks as follows:

java.lang.StackOverflowError
    at com
.fasterxml.jackson.databind.ser.impl.ReadOnlyClassToSerializerMap.typedValueSerializer(ReadOnlyClassToSerializerMap.java:61)
    at com
.fasterxml.jackson.databind.SerializerProvider.findTypedValueSerializer(SerializerProvider.java:588)
    at com
.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:92)
    at com
.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:1887)
    at com
.fasterxml.jackson.databind.util.TokenBuffer.writeObject(TokenBuffer.java:798)
    at org
.mongojack.internal.ObjectIdSerializer.serialize(ObjectIdSerializer.java:49)
    at com
.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:114)
    at com
.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:1887)
    at com
.fasterxml.jackson.databind.util.TokenBuffer.writeObject(TokenBuffer.java:798)
    at org
.mongojack.internal.ObjectIdSerializer.serialize(ObjectIdSerializer.java:49)
    at com
.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:114)
    at com
.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:1887)
    at com
.fasterxml.jackson.databind.util.TokenBuffer.writeObject(TokenBuffer.java:798)
    at org
.mongojack.internal.ObjectIdSerializer.serialize(ObjectIdSerializer.java:49)
    at com
.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:114)
    at com
.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:1887)
    at com
.fasterxml.jackson.databind.util.TokenBuffer.writeObject(TokenBuffer.java:798)
    at org
.mongojack.internal.ObjectIdSerializer.serialize(ObjectIdSerializer.java:49)


I can reproduce the StackOverflowError by doing the following:

ObjectMapper mapper = new ObjectMapper();
MongoJackModule.configure(mapper);
mapper
.writeValueAsString(new ObjectId());


Note that I'm not trying to actually do the above. It only serves as a minimal reproducer of the exception I get in my code.

My questions: Is this a bug? If not, is there any workaround?

Jochen Schalanda

unread,
Mar 17, 2016, 9:19:23 AM3/17/16
to mongo-jackson-mapper
Hi,

I've been running in the exactly same problem using Mongojack 2.6.0 and Jackson 2.7.3. Basically every version after Jackson 2.6.2 shows the same error which can be reproduced by the minimal example Andreas gave in his post.

Did anyone else run into that problem or did even find a solution for it?


Cheers,
Jochen
Reply all
Reply to author
Forward
0 new messages