有没有办法以编程方式告诉杰克逊忽略一个属性?例如,按名称。
我的问题是我正在序列化第三方对象,其中一些具有父/子循环依赖关系,导致
com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError)
因为我不能修改代码,所以打破循环依赖的常用方法对我不起作用。
我正在使用ObjectMapper
and ObjectWriter
:
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.setVisibility(new VisibilityChecker.Std(JsonAutoDetect.Visibility.ANY));
writer = mapper.writerWithDefaultPrettyPrinter();
writer.writeValueAsString(object);
而且我知道它们是高度可定制的,就像我在片段中的序列化包含和可见性一样,但我找不到他们实现类似的方法
mapper.ignoreProperty("parent");