小编典典

JsonMappingException(was java.lang.NullPointerException)

json

我已经搜索了一段时间,但没有找到任何答案,因此我丢失了一些明显的东西,没人写过任何东西,或者遇到了一个不寻常的问题。我希望这是第一个…

我正在使用第三方库(IDMLlib)从以.idml格式存储的Adobe
InDesign文档中提取信息。内容很容易阅读并存储在“ Idml”类型的对象中,其中包含我需要的所有内容。现在,我想使用Jackson
JSON
将此对象发送到Web客户端(浏览器)。

我遇到了两个问题:

1)对象树充满了循环参照。我已经通过在批注中使用混合插件来解决此问题

@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id")

所以现在,如果问题2需要的话,我已经准备好了很多混入工具。

2)序列化时,我不断收到新的特定于对象的错误。

--Output from testMethodsReturnsSomething--
| Failure:  testMethods(package.IdmlServiceTests)
|  com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: de.fhcon.idmllib.api.elements.Idml["document"]->de.fhcon.idmllib.api.elements.Document["tags"]->de.fhcon.idmllib.api.elements.tags.Tags["xmltagList"]->java.util.ArrayList[0]->de.fhcon.idmllib.api.elements.tags.XMLTag["tagColor"]->de.fhcon.idmllib.api.elements.typedefs.InDesignUIColorType["greenValue"])
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:218)
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:183)
at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:155)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:533)
...

我尝试编写自定义的NullValue / NullKey序列化器,但这对NullPointerException没有帮助。

我可以在我的混入中使用注释来处理此问题吗?
还是我可以通过其他方法来序列化此对象?


阅读 864

收藏
2020-07-27

共1个答案

小编典典

您是对的,Double可以处理
值,double不能。就我而言,我的属性是类型,Long但是getter返回的是long值而不是Long值。只要该值不为 null,
就可以接受。但是当该值为 null时 ,jackson无法为序列化 nulllong

只需更改getter以返回a Long而不是将其long固定即可。验证您的吸气剂是否返回a Double而不是double您的情况。

ps:我知道这个问题已经很老了,但是由于我遇到了同样的问题,而且这个问题在Google答案中排名第二。

2020-07-27