groovy
  1. groovy
  2. GROOVY-4860

Enable JsonBuilder to work with objects recursively

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.0
    • Fix Version/s: 1.8.1, 1.9-beta-1
    • Component/s: JSON
    • Labels:
      None
    • Number of attachments :
      0

      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!

        Activity

          People

          • Assignee:
            Guillaume Laforge
            Reporter:
            Axel Fontaine
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: