Ste*_*fen 7 java json nullpointerexception jackson idml
我一直在寻找这个问题但是没有找到任何答案,所以要么我错过了一些如此明显的东西没有人写过任何关于它的东西,或者我遇到了一个不寻常的问题.我希望这是第一次......
我正在使用第三方库(IDMLlib)从以.idml格式存储的Adobe InDesign文档中提取信息.内容很容易读取并存储在"Idml"类型的对象中,其中包含我需要的所有内容.现在,我想使用Jackson JSON将此对象发送到Web客户端(浏览器).
我遇到了两个问题:
1)对象树充满了圆形的引用.我通过使用带有注释的混合来解决这个问题
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id")
Run Code Online (Sandbox Code Playgroud)
所以现在我已经准备好了很多Mix-ins,如果问题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)
...
Run Code Online (Sandbox Code Playgroud)
我已经尝试编写自定义NullValue/NullKey序列化程序,但这对NullPointerException没有帮助.
我可以在我的Mix-ins中使用注释来处理这个问题吗?
还是有另一种方法让我序列化这个对象?
Max*_*e T 17
你是对的,Double可以处理空值,而double不能.在我的情况下,我的属性是类型,Long但getter返回long值而不是Long值.只要值不为空,这是可以接受的.但是当值为null时,jackson无法序列化null值long.
只需更改吸气剂即可返回Long而不是long固定它.验证你的getter是否返回a Double而不是a double.
ps:我知道这个问题已经很老了但是因为我遇到了同样的问题而且这个问题在谷歌的答案中排名第二...似乎公平地回答它的问题比以后更好
| 归档时间: |
|
| 查看次数: |
16555 次 |
| 最近记录: |