0

I'm trying to serialize Javaparser objects with Jackson JSON, but it's pretty complicated as it is a third party library (I can't change/annotate the code) and there are circular dependencies within it.

My project is structured as such :

An object Analysis contains some lists of WrappedNode that may reference each other. Each WrappedNode contains a JavaParser CallableDeclaration.

When I try to map my Analysis, I've got an error :

JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: com.github.javaparser.metamodel.PropertyMetaModel["containingNodeMetaModel"]->com.github.javaparser.metamodel.SimpleNameMetaModel["declaredPropertyMetaModels"]->java.util.ArrayList[0]->com.github.javaparser.metamodel.PropertyMetaModel["containingNodeMetaModel"]...

So, to get rid of the infinite recursion, I know I have to use @JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@id"), which I did on my WrappedNode class, but I think I should also annotate JavaParser classes using Mix-in annotations.

The problem is that there is a lot of fields and a lot of classes, and I don't know which ones to annotate.

Thank's for your help !

Lodart
  • 23
  • 5

1 Answers1

0

You can just use the JsonPrinter class provided by JavaParser. It is a very recent addition (from version 3.2.8 I think) and it could not be perfect but you can use it super, super easily

Federico Tomassetti
  • 2,100
  • 1
  • 19
  • 26
  • This would be perfect, but as I am also using JavaSymbolSolver, I use the maven dependency com.github.javaparser java-symbol-solver-core 0.5.5 So I'm stuck with JP 3.2.4, am I not ? – Lodart Jul 06 '17 at 07:47
  • Technically yes, but given I am the mantainer of the JavaSymbolSolver I can just do a release for you... – Federico Tomassetti Jul 06 '17 at 08:06
  • That would be very very nice :) Thank you very much :) – Lodart Jul 06 '17 at 08:21
  • No problem, we love to help our users! JavaSymbolSolver 0.5.6 has been released and it is based on JavaParser 3.2.10. It normally takes a few hours to propagate to Maven Central. If you are in an hurry you can just clone the repo from GitHub and run ./gradlew install to install a copy locally, otherwise in a few hours you will be able to get it from maven central – Federico Tomassetti Jul 06 '17 at 08:27