groovy
  1. groovy
  2. GROOVY-4984

JsonOutput.toJson(object) does not handle char[] correctly

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.8.0, 1.8.1
    • Fix Version/s: 1.8.2, 1.9-beta-3
    • Component/s: groovy-jdk
    • Labels:
      None
    • Testcase included:
      yes
    • Number of attachments :
      3

      Description

      Currently

      println new JsonBuilder(['a','b','c','d'] as char[]).toString()

      will output

      [{},{},{},{}]

      since the primitive class char has no properties (other than class).

      My solution is to call toString on the object if there are no properties left. I have attached an updated JsonOutput.groovy and a fixed test.

      1. GROOVY-4984.patch
        1 kB
        Seth Miller
      2. JsonOutput.groovy
        6 kB
        Seth Miller
      3. JsonOutputTest.groovy
        9 kB
        Seth Miller

        Activity

        Guillaume Laforge made changes -
        Field Original Value New Value
        Assignee Guillaume Laforge [ guillaume ]
        Hide
        Seth Miller added a comment -

        Here is a patch file with my changes, if that helps.

        Show
        Seth Miller added a comment - Here is a patch file with my changes, if that helps.
        Seth Miller made changes -
        Attachment GROOVY-4984.patch [ 56611 ]
        Guillaume Laforge made changes -
        Fix Version/s 1.8.2 [ 17495 ]
        Fix Version/s 1.9-beta-2 [ 17494 ]
        Hide
        Guillaume Laforge added a comment -

        I've got a slightly different view on this issue.
        I think char[] should be represented as a String, ie. ['a','b','c','d'] as char[] would be "abcd".

        Show
        Guillaume Laforge added a comment - I've got a slightly different view on this issue. I think char[] should be represented as a String, ie. ['a','b','c','d'] as char[] would be "abcd".
        Hide
        Seth Miller added a comment -

        I'm afraid I would have to disagree. If someone has gone through the trouble of dealing with a char array, it is likely that they wanted to work with the individual chars. At least this was the case for me.

        Show
        Seth Miller added a comment - I'm afraid I would have to disagree. If someone has gone through the trouble of dealing with a char array, it is likely that they wanted to work with the individual chars. At least this was the case for me.
        Hide
        Guillaume Laforge added a comment -

        Ok fair enough.

        Show
        Guillaume Laforge added a comment - Ok fair enough.
        Hide
        Guillaume Laforge added a comment -

        Implemented as a JSON array of single-character strings

        Show
        Guillaume Laforge added a comment - Implemented as a JSON array of single-character strings
        Guillaume Laforge made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

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

            Dates

            • Created:
              Updated:
              Resolved: