杰克逊 - 序列化包含空元素的列表(Jackson - serializing a list containing null elements)
我正在使用Jackson 2.4将对象序列化为JSON。
当我序列化对象列表时,如果某些元素为null,则结果JSON
字符串包含一些“null”字符串。
如何防止"null"
元素被序列化?ObjectMapper
有没有配置? 我已经设置了"setSerializationInclusion(Include.NON_NULL)"
!这是我的代码:
List<String> strings = new ArrayList<>(); strings.add("string 1"); strings.add("string 2"); strings.add(null); strings.add(null);
序列化之后我得到了这个:
[string 1, string 2, null, null]
如何在没有“null”的情况下获取JSON字符串?
[string 1, string 2]
I'm using Jackson 2.4 to serialize objects to JSON.
When I serialize a list of objects, having some elements are null, the resultJSON
string contains some "null" strings.
How do I prevent"null"
elements from being serialized? Is there any configuration forObjectMapper
? I have already set"setSerializationInclusion(Include.NON_NULL)"
!Here is my code :
List<String> strings = new ArrayList<>(); strings.add("string 1"); strings.add("string 2"); strings.add(null); strings.add(null);
After serializing I got this :
[string 1, string 2, null, null]
How do I get the JSON string without "null"?
[string 1, string 2]
原文:https://stackoverflow.com/questions/27246955
最满意答案
当您拥有不兼容的第三方版本时,通常会出现此类问题。
在这种情况下,尝试“对齐”弹簧罐 - 使用相同的弹簧版本。 这应该可以解决您的问题。
希望这可以帮助。
JmsResourceHandler extends org.springframework.transaction.support.ResourceHolderSupport; and ResourceHolderSupport implements ResourceHolder.
ResourceHolderSupport was in two jars:
- Spring-dao-2.0.8
- Spring-tx-3.0.5.Release
I solved the problem by using Spring-orm-3.0.5.Release, instead of spring-hibernate3-2.0.8,.
相关问答
更多-
看起来你正在使用播放服务:8.1.0,你应该使用9.0.1,你也应该使用特定的播放服务库,例如:play-services-gcm而不仅仅是play-services。 我建议你尝试firebase-messaging:9.0.1实现更简单,它是play-services-gcm中可用功能的超集。 有关更多信息,请参阅文档 。 Looks like you are using play-services:8.1.0, you should be using 9.0.1, also you should be ...
-
事实证明,有更多的Infinispan配置需要,我不知道它存在。 在事务标记中(在默认配置下),即使我设置了transanction manager查找,我也必须明确地添加属性transactionMode="TRANSACTIONAL" 。 我还使用Hibernate使用的缓存的默认配置,它们的名称是: entity , local-query和timestamp 。 在hibernate-infinispan.jar中有一个名为infinispan-configs.xml的文件,它有助于设置所需的配置。 ...
-
Java 8中的IncompatibleClassChangeError(Lambda表达式)(IncompatibleClassChangeError in Java 8 (Lambda expression))[2023-03-22]
eclipse在支持java8方面存在问题。 我已成功编译并在命令提示符下运行 D:\ tools \ java \ jdk1.8.0_32Bit \ bin \ javac com / ahmetk / java8 / Hello.java D:\ tools \ java \ jdk1.8.0_32Bit \ bin \ java -cp。 com.ahmetk.java8.Hello 12 12你好12 12 eclipse has problem in supporting java8. I hav ... -
Spring WAR部署中的IncompatibleClassChangeError(IncompatibleClassChangeError on Spring WAR deploy)[2023-08-28]
根据Java API,在以下情况下抛出IncompatibleClassChangeError : ...当某个类定义发生不兼容的类更改时。 此后正在执行的方法所依赖的某个类的定义已经发生了变化。 如果我正确地解释这一点,我会冒昧地说你有一些无可比拟的JAR。 我会检查你的应用服务器上的类路径。 It seems this problem was caused by other applications running in the same instance of tomcat using a diffe ... -
Android Things上的IncompatibleClassChangeError(IncompatibleClassChangeError on Android Things)[2022-05-23]
从预览7开始,许多外围I / O接口都从抽象类转换为接口。 这样做是为了更好地促进应用程序的可测试性,因为界面更容易模拟。 请务必更新您的应用以使用Preview 7 SDK: dependencies { compileOnly 'com.google.android.things:androidthings:0.7-devpreview' } 然后修改您的回调以实现该接口: private class ButtonCallback implements GpioCallback { @ ... -
一个原因可能是您的类路径中有两个包具有相同的“TransactionSynchronization”类。 你能尝试以下吗? 你在WSO2_HOME / repository / components / dropins目录中有什么? 删除dropins中的所有jar并重新启动服务器并重新检查该问题。 如果错误仍然存在,请尝试从WSO2_HOME / repository / components / lib和WSO2_HOME / repository / components / dropins中删除sp ...
-
所以我发现我的IDE intellij-dea搞砸了我的构建。 我认为,因为我已经配置了maven,它只是在引擎盖下运行纯maven。 在我的IDE中,我已经为我的maven依赖项之前配置了一个已安装的Axis2-1.6.0目录。 Axis-2是从我的应用程序的旧版本中遗留下来的,并且包含许多依赖项的副本,包括Neethi ,我已经在其他地方列出了其中作为CXF的此错误的潜在来源。 So I it turns out my IDE intellij-dea was messing up my build. ...
-
你有没有使用Java 7? 使用当您拥有不兼容的第三方版本时,通常会出现此类问题。 在这种情况下,尝试“对齐”弹簧罐 - 使用相同的弹簧版本。 这应该可以解决您的问题。 希望这可以帮助。 JmsResourceHandler extends org.springframework.transaction.support.ResourceHolderSupport; and ResourceHolderSupport implements ResourceHolder. ResourceHolderSupport was in two ja ...
OpenPojo IncompatibleClassChangeError异常(OpenPojo IncompatibleClassChangeError Exception)[2022-01-03]
您是否尝试将ASM 5.0.3或更高版本添加为依赖项? 似乎ASM的旧版本正在被拉入。 Have you tried to add the ASM 5.0.3 or higher as a dependency? It seems an older version for ASM is getting pulled in.相关文章
更多- JSON部分序列化(二)
- Python 列表(list)操作
- List用完后需要赋null吗
- Java序列化
- FreeMarker集合(List、Map)
- A Great List of Windows Tools
- List的size大于0,但是取到的值为空
- Python内建函数(A)
- redis整合spring示例二—java操作redis(存对象及List)
- [转]So You Want To Be A Producer
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。