这个简单的代码:
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));
}
导致此异常:
Exception in thread "main" java.lang.StackOverflowError
at java.lang.Enum.ordinal(Enum.java:103)
at com.fasterxml.jackson.databind.MapperFeature.getMask(MapperFeature.java:259)
at com.fasterxml.jackson.databind.cfg.MapperConfig.isEnabled(MapperConfig.java:110)
at com.fasterxml.jackson.databind.SerializationConfig.getAnnotationIntrospector(SerializationConfig.java:404)
at com.fasterxml.jackson.databind.SerializerProvider.getAnnotationIntrospector(SerializerProvider.java:307)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.createContextual(MapSerializer.java:235)
at com.fasterxml.jackson.databind.SerializerProvider._handleContextual(SerializerProvider.java:968)
at com.fasterxml.jackson.databind.SerializerProvider.findValueSerializer(SerializerProvider.java:447)
at com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.findAndAddSerializer(PropertySerializerMap.java:38)
at com.fasterxml.jackson.databind.ser.std.MapSerializer._findAndAddDynamic(MapSerializer.java:516)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeFields(MapSerializer.java:386)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:312)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:26)
etc...
而对于我的生活,我无法弄清楚为什么。我通过搜索找到的只是人们因为递归引用而遇到问题,但在这种情况下并非如此。