I am new using Json lib. I am trying to serialize a bean with a cycle in its hierarchy. Obviously, i am getting the Json Exception 'There is a cycle in the hierarchy!' and I have read that the way to solve this could be adding a new CycleDetectionStrategy.
Can anybody tell me how can i do this? Do i have to include it in the Json lib config? An example would be specially welcome.
Thanks in advance,
Carlos
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
JsonConfig has a CycleDetectionStrategy that defaults to CycleDetectionStrategy.STRICT, there are two other strategies you may choose: LENIENT & NOPROP, besides creating your own and register it. You may register a new CycleDetectionStrategy with the following code
Hello everybody,
I am new using Json lib. I am trying to serialize a bean with a cycle in its hierarchy. Obviously, i am getting the Json Exception 'There is a cycle in the hierarchy!' and I have read that the way to solve this could be adding a new CycleDetectionStrategy.
Can anybody tell me how can i do this? Do i have to include it in the Json lib config? An example would be specially welcome.
Thanks in advance,
Carlos
JsonConfig has a CycleDetectionStrategy that defaults to CycleDetectionStrategy.STRICT, there are two other strategies you may choose: LENIENT & NOPROP, besides creating your own and register it. You may register a new CycleDetectionStrategy with the following code
JsonConfig jsonConfig = new JsonConfig()
jsonConfig.setCycleDetectionStrategy( CycleDetectionStrategy.LENIENT )
JSON json = JSONSerializer.toJSON( yourBean, jsonConfig )
Cheers,
Andres
Thank you very much Andres, i think this will be very useful for me.
Cheers,
Carlos