Menu

Adding a new CycleDetectionStrategy

Help
cuetumayu
2008-03-12
2013-04-29
  • cuetumayu

    cuetumayu - 2008-03-12

    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

     
    • aalmiray

      aalmiray - 2008-03-12

      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

       
    • cuetumayu

      cuetumayu - 2008-03-13

      Thank you very much Andres, i think this will be very useful for me.

      Cheers,

      Carlos

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.