java - How to json with circular references? -
i have following class construct creating circular dependency. in general, jackson
library should able handle these circular dependencies.
i'm looking way not having use annotations on every class has circularities, somehow configure in objectmapper
.
@jsonidentityinfo(generator = objectidgenerators.intsequencegenerator.class, property = "@id") abstract class shape; class line extends shape { //a line can connect 2 circles circle from, to; } class circle extends shape { // circle can have many lines connected list<line> lines; }
i serialize list, contains both circles
, lines
:
list<shape> shapes; objectmapper om = new objectmapper().setdefaulttyping();
it possible configure id generation globally on mapper?
no. since not types can have ids (only pojo types, is, collection
s, map
s , arrays out), , since details may vary, there no "default id" setting unlike type ids.