Is there any way of programatically telling jackson to ignore a property? For instance, by name.
My problem is that I'm serializing third party objects, some of which have parent/child cyclic dependencies that cause
com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError)
Because I can't modify the code, the usual ways of breaking cyclic dependencies don't work for me.
I'm using an 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);
And I know they're highly customizable, as with the serialization inclusion and visibility that I have in the snippet, but I can't find they way of achieving something like
mapper.ignoreProperty("parent");