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

JSon serialization with unicode characters fail

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.3.1, 2.3.2, 2.3.3, 2.3.4
    • Fix Version/s: 2.3.5, 2.4.0-beta-2
    • Component/s: JSON
    • Labels:
      None
    • Environment:
      Groovy Version: 2.3.3 JVM: 1.8.0_05 Vendor: Oracle Corporation OS: Linux
      java version "1.8.0_05"
      Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

      Description

      Json serialiation with Greek characters fails

      To reproduce:

      Object o1 = ["ΑΦΟΙ ΚΟΛΛΙΑ ΚΡΕΩΠΟΛΕΙΟ ΤΑΒΕΡΝΑ"]
      println "o1=${new JsonBuilder(o1).toString()}"
      
      Object o2 = ["ΑΦΟΙ ΚΟΛΛΙΑ ΚΡΕΩΠΟΛΕΙΟ ΤΑΒΕΡΝΑ", "Καλύβια Θορικού"]
      println "o2=${new JsonBuilder(o2).toString()}"
      

      Outputs:

      o1=["\u0391\u03a6\u039f\u0399 \u039a\u039f\u039b\u039b\u0399\u0391 \u039a\u03a1\u0395\u03a9\u03a0\u039f\u039b\u0395\u0399\u039f \u03a4\u0391\u0392\u0395\u03a1\u039d\u0391"]
      
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 255
      	at groovy.json.internal.CharBuf.doAddJsonEscapedString(CharBuf.java:533)
      	at groovy.json.internal.CharBuf.addJsonEscapedString(CharBuf.java:394)
      	at groovy.json.internal.CharBuf.addJsonEscapedString(CharBuf.java:357)
      	at groovy.json.JsonOutput.writeCharSequence(JsonOutput.java:309)
      	at groovy.json.JsonOutput.writeObject(JsonOutput.java:260)
      	at groovy.json.JsonOutput.writeIterator(JsonOutput.java:446)
      	at groovy.json.JsonOutput.writeObject(JsonOutput.java:272)
      	at groovy.json.JsonOutput.toJson(JsonOutput.java:190)
      	at groovy.json.JsonBuilder.toString(JsonBuilder.groovy:273)
      	at groovy.json.JsonBuilder$toString.call(Unknown Source)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
      	at Draft.main(Draft.groovy:37)
      

        Attachments

        1. test.groovy
          0.3 kB
          Mathieu Carbou

          Activity

            People

            • Assignee:
              guillaume Guillaume Sauthier
              Reporter:
              kha Mathieu Carbou
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: