Jettison
  1. Jettison
  2. JETTISON-96

MappedNamespaceConvention with non-string attributes fail

    Details

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

      Description

      If an attribute is not a string, the MappedNamespaceConvention fails (see @made member, if its value is changed to "true" it works).

      {"shot":{"@team": "1", "@player": "1", "@systemTime": "01:19:35", "@gameTime": "01:19:35", "@eventTime": "01:19:35.000", "@type": "4", "@x": "123", "@y": "55", "@made": true}}

      java.lang.ClassCastException: java.lang.Boolean
      at org.codehaus.jettison.mapped.MappedNamespaceConvention.processAttributesAndNamespaces(MappedNamespaceConvention.java:119)
      at org.codehaus.jettison.Node.<init>(Node.java:55)
      at org.codehaus.jettison.mapped.MappedXMLStreamReader.processElement(MappedXMLStreamReader.java:147)
      at org.codehaus.jettison.mapped.MappedXMLStreamReader.next(MappedXMLStreamReader.java:77)
      at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:192)
      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:360)
      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:332)
      at com.xxx.livefeed.esb.TestComponent.transform(TestComponent.java:62)
      at org.apache.servicemix.components.util.TransformComponentSupport.processFirstExchange(TransformComponentSupport.java:90)
      at org.apache.servicemix.components.util.TransformComponentSupport.onMessageExchange(TransformComponentSupport.java:64)
      at org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.processInBound(DeliveryChannelImpl.java:632)
      at org.apache.servicemix.jbi.nmr.flow.AbstractFlow.doRouting(AbstractFlow.java:185)
      at org.apache.servicemix.jbi.nmr.flow.seda.SedaFlow.doRouting(SedaFlow.java:168)
      at org.apache.servicemix.jbi.nmr.flow.seda.SedaQueue$1.run(SedaQueue.java:134)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:651)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:676)
      at java.lang.Thread.run(Thread.java:613)

        Activity

        Hide
        David Wood added a comment -

        This bit me as well and caused a lot of things to break in my system when upgrading. Clients that used to send JSON boolean attributes without quotes (e.g. {"obj":{"@enabled":false}} suddenly started getting class cast exceptions.

        I've implemented a simple fix for this. It changes

        String strValue = (String) o;

        to:

        String strValue = (o == null ? null : o.toString());

        This seems to work for the boolean attributes at least.

        Show
        David Wood added a comment - This bit me as well and caused a lot of things to break in my system when upgrading. Clients that used to send JSON boolean attributes without quotes (e.g. {"obj":{"@enabled":false}} suddenly started getting class cast exceptions. I've implemented a simple fix for this. It changes String strValue = (String) o; to: String strValue = (o == null ? null : o.toString()); This seems to work for the boolean attributes at least.
        Hide
        David Wood added a comment -

        patch file for MappedNamespaceConvention

        Show
        David Wood added a comment - patch file for MappedNamespaceConvention
        Hide
        Stefan Vladov added a comment -

        Guys shouldn't this be also merged in the badgerfish convention?
        In fact badgerfish implementation currently does not accept even non-string elements because of the same String cast in BadgerFishXMLStreamReader#processKey.

        This is probably not the right place to ask but are there any plans for non-string data types support in badgerfish? We could easily add the whole TypeConverter thing in there. What do you think?

        Regards,
        Stefan

        Show
        Stefan Vladov added a comment - Guys shouldn't this be also merged in the badgerfish convention? In fact badgerfish implementation currently does not accept even non-string elements because of the same String cast in BadgerFishXMLStreamReader#processKey. This is probably not the right place to ask but are there any plans for non-string data types support in badgerfish? We could easily add the whole TypeConverter thing in there. What do you think? Regards, Stefan
        Hide
        Roland Müller added a comment -

        The same happens to me with Integer attributes. I get "java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String" at the
        String strValue = (String) o;
        line.

        Show
        Roland Müller added a comment - The same happens to me with Integer attributes. I get "java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String" at the String strValue = (String) o; line.

          People

          • Assignee:
            Sergey Beryozkin
            Reporter:
            Harri Hohteri
          • Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: