52.4. 设置序列化 include 选项
如果您要将 pojo 放入 XML,并且 pojo 有一些带有 null 值的字段。并且您要跳过这些 null 值,然后您需要在 pojo 上设置注解,
@JsonInclude(Include.NON_NULL) public class MyPojo { ... }
但这需要您在 pojo 源代码中包含该注解。您还可以配置 Camel JacksonXMLDataFormat 来设置 include 选项,如下所示:
JacksonXMLDataFormat format = new JacksonXMLDataFormat(); format.setInclude("NON_NULL");
或者从 XML DSL 中将其配置为
<dataFormats> <jacksonxml id="jacksonxml" include="NON_NULL"/> </dataFormats>