java - Json serialization of a simple map is causing stackOverflowErrors -


this simple code:

public static void test() throws jsonprocessingexception {     map<object, object> request = new hashmap<>();     request.put("id", "test_0001");     request.put("version", 1);      map<object, object> fields = new hashmap<>();     fields.put("uri", "blah/blah");     fields.put("owner", "me");      request.put("fields", request);      objectmapper om = new objectmapper();     system.out.println(om.writevalueasstring(request)); } 

is causing exception:

exception in thread "main" java.lang.stackoverflowerror     @ java.lang.enum.ordinal(enum.java:103)     @ com.fasterxml.jackson.databind.mapperfeature.getmask(mapperfeature.java:259)     @ com.fasterxml.jackson.databind.cfg.mapperconfig.isenabled(mapperconfig.java:110)     @ com.fasterxml.jackson.databind.serializationconfig.getannotationintrospector(serializationconfig.java:404)     @ com.fasterxml.jackson.databind.serializerprovider.getannotationintrospector(serializerprovider.java:307)     @ com.fasterxml.jackson.databind.ser.std.mapserializer.createcontextual(mapserializer.java:235)     @ com.fasterxml.jackson.databind.serializerprovider._handlecontextual(serializerprovider.java:968)     @ com.fasterxml.jackson.databind.serializerprovider.findvalueserializer(serializerprovider.java:447)     @ com.fasterxml.jackson.databind.ser.impl.propertyserializermap.findandaddserializer(propertyserializermap.java:38)     @ com.fasterxml.jackson.databind.ser.std.mapserializer._findandadddynamic(mapserializer.java:516)     @ com.fasterxml.jackson.databind.ser.std.mapserializer.serializefields(mapserializer.java:386)     @ com.fasterxml.jackson.databind.ser.std.mapserializer.serialize(mapserializer.java:312)     @ com.fasterxml.jackson.databind.ser.std.mapserializer.serialize(mapserializer.java:26) etc... 

and life of me cant figure out why. have found searching people having issues because of recursive references, that's not case in instance.

you have put map itself

request.put("fields", request); 

this makes infinite loop. shouldn't put map itself.

you meant write

request.put("fields", fields); 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -