Jettison
  1. Jettison
  2. JETTISON-93

java.lang.ClassCastException: org.codehaus.jettison.json.JSONArray cannot be cast to java.lang.String when the text value of "$" is an array of strings

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.3.1
    • Labels:
      None
    • Number of attachments :
      1

      Description

      Hi,

      I have the following json string produced from XML:

      {"ipo:purchaseOrder":{"billTo":{"zip":

      {"$":"95819"}

      ,"@xsi:type":"ipo:USAddress","$":[" "," "," "," "," "," "],"street":

      {"$":"8 Oak Avenue"}

      ,"name":

      {"$":"Robert Smith"}

      ,"state":

      {"$":"PA"}

      ,"city":{"$":"Old Town"}},"@orderDate":"1999-12-01","items":{"$":[" "," "],"item":{"ipo:comment":

      {"$":"Want this for the holidays"}

      ,"@partNum":"833-AA","$":[" "," "," "," "," "," "],"quantity":

      {"$":"1"}

      ,"shipDate":

      {"$":"1999-12-05"}

      ,"USPrice":

      {"$":"99.95"}

      ,"productName":

      {"$":"Lapis necklace"}

      }},"$":[" "," "," "],"shipTo":{"@xsi:type":"ipo:UKAddress","$":[" "," "," "," "," "],"street":

      {"$":"47 Eden Street"}

      ,"name":

      {"$":"Helen Zoe"}

      ,"postcode":

      {"$":"CB1 1JR"}

      ,"@exportCode":"1","city":{"$":"Cambridge"}},"@xmlns":

      {"ipo":"http://www.example.com/IPO","xsi":"http://www.w3.org/2001/XMLSchema-instance"}

      ,"@xsi:schemaLocation":"http://www.example.com/IPO ipo.xsd"}}

      Please note some of the text value is a string array instead of string. And it hits the "TODO" (the TODO is right in class org.codehaus.jettison.badgerfish.BadgerFishXMLStreamReader:

      private void processKey(String nextKey, Object newObj) throws JSONException, XMLStreamException {
      if (nextKey.equals("$"))

      { event = CHARACTERS; // TODO I think there is a possibility this could be array currentText = (String) newObj; return; }


      ..

      The stacktrace is:
      java.lang.ClassCastException: org.codehaus.jettison.json.JSONArray cannot be cast to java.lang.String
      at org.codehaus.jettison.badgerfish.BadgerFishXMLStreamReader.processKey(BadgerFishXMLStreamReader.java:96)
      at org.codehaus.jettison.badgerfish.BadgerFishXMLStreamReader.processElement(BadgerFishXMLStreamReader.java:86)
      at org.codehaus.jettison.badgerfish.BadgerFishXMLStreamReader.next(BadgerFishXMLStreamReader.java:66)
      at org.apache.tuscany.sca.common.xml.stax.impl.XMLStreamSerializer.serializeNode(XMLStreamSerializer.java:353)
      at org.apache.tuscany.sca.common.xml.stax.impl.XMLStreamSerializer.serialize(XMLStreamSerializer.java:94)
      at org.apache.tuscany.sca.common.xml.stax.StAXHelper.save(StAXHelper.java:195)
      at org.apache.tuscany.sca.databinding.json.JSONTransformerTestCase.testXML2JSON(JSONTransformerTestCase.java:95)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

        Activity

        Hide
        Raymond Feng added a comment -

        Attached is the java file with a fix. Please review. I didn't use a diff format as I directly changed the code from the 1.2 source distro.

        Show
        Raymond Feng added a comment - Attached is the java file with a fix. Please review. I didn't use a diff format as I directly changed the code from the 1.2 source distro.
        Raymond Feng made changes -
        Field Original Value New Value
        Attachment BadgerFishXMLStreamReader.java [ 48289 ]
        Sergey Beryozkin made changes -
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Sergey Beryozkin [ sergey_beryozkin ]
        Fix Version/s 1.3.1 [ 18239 ]

          People

          • Assignee:
            Sergey Beryozkin
            Reporter:
            Raymond Feng
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: