Skip to content

Jackson serializing: Get list of processed objects

For a special case, I need to know which “source objects” of the object tree Jackson processed during serialization.

public class A {}

public class B {
   private A a;

public class Main {
   public void doIt() {
      B b = new B();
      b.a = new A();

      // Here I need to get the list of all processed objects from mapper m, i.e. [a,b]

I think there is some internal list, because Jackson might reuse already serialized objects if they are referenced multiple times in the object tree. Can I get this list? Or is it possible to build my own list by an event listener which is called for every serialized object?



I found a solution with a PropertyFilter. I’m collecting all the objects seen in serializeAsField and at the end I’ve a complete list of traversed objects.

User contributions licensed under: CC BY-SA
2 People found this is helpful