Announcement Announcement Module
Collapse
No announcement yet.
JiBX - marshall/unmarshall Collection Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JiBX - marshall/unmarshall Collection

    Using the JiBX endpoint - can I specify to marshall or unmarshall a java.util.Collection type? The objects within that Collection will be binded in JiBX.... but how will it resolve them?

    Seems that I would need to create my own wrapper class that aggregates the Collection just to have a class name to set as a base marhsall/unmarshall class for the endpoint?

  • #2
    No, you don't need to write a wrapper class. Read this: http://jibx.sourceforge.net/tutorial...-collects.html

    Comment


    • #3
      Your reference is to JiBX bindings - so perhaps I was unclear - how to bind Collections in JiBX is not my question.

      My question refers to the Spring WS endpoint definition in the application context file - where the 'targetClass' is set for the JibxMarshaller bean. We have tried to set this value to 'java.util.Collection' and the deployment fails - we have tried to set this value to 'java.util.ArrayList' and the deployment fails - so, how then, without writing a wrapper class of my own [that I map in JiBX] can I use the the generically supported types?

      If I write a wrapper class such as 'CollectionMessage' then put the collection inside, then properly map 'CollectionMessage' in the jibx binding file all is well.

      Also - what about types such as 'java.lang.Boolean'? If I write a JiBX serializer for such a type how do I reference the serializer?

      Also - what is your suggestion for methods that do not need to return anything? Such as a VOID return? Is that bad design since SOAP should always return something - such as at least 'true'/'false' [leads back to my Boolean question!]?

      thanks!
      Ron

      Comment


      • #4
        Originally posted by rwilcom
        My question refers to the Spring WS endpoint definition in the application context file - where the 'targetClass' is set for the JibxMarshaller bean. We have tried to set this value to 'java.util.Collection' and the deployment fails - we have tried to set this value to 'java.util.ArrayList' and the deployment fails - so, how then, without writing a wrapper class of my own [that I map in JiBX] can I use the the generically supported types?

        If I write a wrapper class such as 'CollectionMessage' then put the collection inside, then properly map 'CollectionMessage' in the jibx binding file all is well.
        Within XML schema, there are only strongly-named collections. There is no such thing as a generic collection. For example, this doesn't exist:

        Code:
        <list>
          <customer id="1"/>
          <customer id="2"/>
        </list>
        You must always define your own parent element:

        Code:
        <customers>
          <customer id="1"/>
          <customer id="2"/>
        </customers>
        This means that you must always write such a Wrapper class. And this is actually a good thing, since the SOAP WS-I Basic Profile tells us to only add one child to a SOAP Body (i.e. the customers, and not all customer elements individually).

        Originally posted by rwilcom
        Also - what about types such as 'java.lang.Boolean'? If I write a JiBX serializer for such a type how do I reference the serializer?
        Such a boolean value must always be contained in a element as well, e.g.

        Code:
        <returnValue>1</returnValue>
        I'm not exactly sure how you would do that with Jibx, but I'm not expert. Perhaps the easiest way would be to use one of the non-marshalling endpoint classes, and write the result yourself.

        There is a best practice here: try and focus on the XML you receive and respond with. I always try to create the XML first, to determine what it must look like, and then I map that to my classes. The XML is important; the classes (from a WS perspective) are not.

        Originally posted by rwilcom
        Also - what is your suggestion for methods that do not need to return anything? Such as a VOID return? Is that bad design since SOAP should always return something - such as at least 'true'/'false' [leads back to my Boolean question!]?
        In SOAP lingo, this is known as a One Way operation. Basically, you don't any soap message. In the AbstractMarshallingPayloadEndpoint, you just return null, and no response will be created. You don't have to confirm every operation with something like a boolean, if anything goes wrong, you can respond with a fault.

        Cheers,

        Comment


        • #5
          Jibx - using supported object/primitive types

          Hello - more on this problem (but no longer relating to Collections); how do I specify in the context deployment file that I want to marshal back a standard supported Jibx type such as a java.lang.Object or a primitive such as 'long'??

          If I do this:
          <bean id="myJibXMarhsallerForObject" class="org.springframework.oxm.jibx.JibxMarshaller ">
          <property name="targetClass" value="java.lang.Object"/>
          <bean>

          I get an error during deployment that the class cannot be found in the jibx bindings; however, java.lang.Object does not need to be bound since it is supported by default (it should automatically use a toString()/String contructor for marshalling). I tried to fake it out by defining java.lang.Object in my binding file, but this didn't help.

          Also - what if I wanted to marshal a 'long' primitive? How do I specifiy this in the bean definition for the JibxMarshaller class?

          thanks!
          Ron

          Comment


          • #6
            Originally posted by rwilcom
            Hello - more on this problem (but no longer relating to Collections); how do I specify in the context deployment file that I want to marshal back a standard supported Jibx type such as a java.lang.Object or a primitive such as 'long'??
            Like I've asked before: what do you want the XML to look like? Let's say you want to return a long value like 42:

            Code:
            <SOAP-ENV:Envelope>
              <SOAP-ENV:Body>
                42
              </SOAP-ENV:Body>
            </SOAP-ENV:Envelope>
            The above is an invalid SOAP message: in SOAP, the body should have one element child, like so:

            Code:
            <SOAP-ENV:Envelope>
              <SOAP-ENV:Body>
                <returnvalue>
                  42
                <returnvalue>
              </SOAP-ENV:Body>
            </SOAP-ENV:Envelope>
            Just as with the boolean return value in my earlier response, I do not know how to accomplish this in Jibx. Perhaps the Jibx mailing list can be of help.

            Comment

            Working...
            X