Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4860

Enable JsonBuilder to work with objects recursively

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.8.0
    • 1.8.1, 1.9-beta-1
    • JSON
    • None

    Description

      Currently this code:

      def myObject = new MyObject()
      
      def json = new JsonBuilder();
      json myObject;
      println JsonOutput.prettyPrint(json.toString())
      

      Prints something like:

      [
          "MyObject@28db23f1"
      ]
      

      My suggestion:
      Introspect the object and transfer each property to json, with recursive calls for objects.

      Having looked at JsonOutput.groovy and the toJson(object) method this should be easy to implement and hugely useful!

      Attachments

        Activity

          People

            guillaume Guillaume Sauthier
            axel.fontaine Axel Fontaine
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: