gpt4 book ai didi

java - Jackson:通过 writeValueAsString 对象到字符串:NPE

转载 作者:行者123 更新时间:2023-11-30 10:41:07 24 4
gpt4 key购买 nike

我正在尝试使用 Jackson 解析器将 Java 对象转换为 JSON。原始对象通过 protobuf 传给我,并包含一些特定于 Jackson 的@annotations。

当我调用 String jsonView = objectMapper.writeValueAsString(values);

我得到这个异常。该对象不包含任何递归值,所以我不清楚为什么我会看到这个错误(甚至这个代码路径)。

ObjectMapper 配置为:objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);(尽管删除它似乎并没有改变任何东西)

java.lang.NullPointerException: null at com.fasterxml.jackson.databind.type.ResolvedRecursiveType.equals(ResolvedRecursiveType.java:103) at com.fasterxml.jackson.databind.type.TypeBindings$AsKey.equals(TypeBindings.java:458) at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:940) at com.fasterxml.jackson.databind.util.LRUMap.get(LRUMap.java:68) at com.fasterxml.jackson.databind.type.TypeFactory._fromClass(TypeFactory.java:1211) at com.fasterxml.jackson.databind.type.TypeFactory._fromParamType(TypeFactory.java:1384) at com.fasterxml.jackson.databind.type.TypeFactory._fromAny(TypeFactory.java:1154) at com.fasterxml.jackson.databind.type.TypeFactory._resolveSuperInterfaces(TypeFactory.java:1298) at com.fasterxml.jackson.databind.type.TypeFactory._fromClass(TypeFactory.java:1243) at com.fasterxml.jackson.databind.type.TypeFactory._fromAny(TypeFactory.java:1150) at com.fasterxml.jackson.databind.type.TypeFactory._resolveSuperInterfaces(TypeFactory.java:1298) at com.fasterxml.jackson.databind.type.TypeFactory._fromClass(TypeFactory.java:1247) at com.fasterxml.jackson.databind.type.TypeFactory._fromAny(TypeFactory.java:1150) at com.fasterxml.jackson.databind.type.TypeFactory.constructType(TypeFactory.java:618) at com.fasterxml.jackson.databind.cfg.MapperConfig.constructType(MapperConfig.java:290) at com.fasterxml.jackson.databind.cfg.MapperConfig.introspectClassAnnotations(MapperConfig.java:320) at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.removeIgnorableTypes(BeanSerializerFactory.java:714) at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.findBeanProperties(BeanSerializerFactory.java:573) at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.constructBeanSerializer(BeanSerializerFactory.java:390) at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.findBeanSerializer(BeanSerializerFactory.java:273) at com.fasterxml.jackson.databind.ser.BeanSerializerFactory._createSerializer2(BeanSerializerFactory.java:225) at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:159) at com.fasterxml.jackson.databind.SerializerProvider._createUntypedSerializer(SerializerProvider.java:1272) at com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1243) at com.fasterxml.jackson.databind.SerializerProvider.findValueSerializer(SerializerProvider.java:535) at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.resolve(BeanSerializerBase.java:332) at com.fasterxml.jackson.databind.ser.SerializerCache.addAndResolveNonTypedSerializer(SerializerCache.java:174) at com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1254) at com.fasterxml.jackson.databind.SerializerProvider.findValueSerializer(SerializerProvider.java:535) at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.resolve(BeanSerializerBase.java:332) at com.fasterxml.jackson.databind.ser.SerializerCache.addAndResolveNonTypedSerializer(SerializerCache.java:174) at com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1254) at com.fasterxml.jackson.databind.SerializerProvider.findValueSerializer(SerializerProvider.java:535) at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.resolve(BeanSerializerBase.java:332) at com.fasterxml.jackson.databind.ser.SerializerCache.addAndResolveNonTypedSerializer(SerializerCache.java:197) at com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1233) at com.fasterxml.jackson.databind.SerializerProvider.findValueSerializer(SerializerProvider.java:499) at com.fasterxml.jackson.databind.SerializerProvider.findTypedValueSerializer(SerializerProvider.java:697) at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:270) at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3672) at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3048)

最佳答案

已在最新版本中修复(参见 2.8.1 或更高版本): https://github.com/FasterXML/jackson-databind/issues/1302

关于java - Jackson:通过 writeValueAsString 对象到字符串:NPE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38615468/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com