Announcement Announcement Module
No announcement yet.
The best Marshalling/UnMarshalling tool to use... Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • The best Marshalling/UnMarshalling tool to use...

    Hi all,

    I see Spring-xml support a few marshall/unmarshall technologies.
    I am currently using Xstream, however, the're saying its not really suited for WS usage. We will probably have to incorporate WS into our app at some stage.
    Which tool then would you guys suggest for handling the XML payloads?
    I need to convert the payloads to POJO's really

  • #2
    I started to look at Castor which was really quick to get up and running but went with JAXB in the end because it get's shipped with the JDK. I've managed to Marshall and UnMarshall with it quite easily using the annotations support


    • #3
      haha, hey...
      thanx for that, i like quick and easy
      I will give it a bash, not having to import yet another dependancy is a bonus for JAXB but yeah I do agree, Castor seems pretty simple to get going.
      I will check both, thanx again...


      • #4
        I recommend JAXB2 - it generates nice annotated POJOs and JAXB2 annotations are simple and elegant.

        First - I've used these annotations to annotate Axis1 generated classes and all went smoothly - JAXB2 pojos marshalled to XML and this XML was unmarshalled to hand-annotated Axis1 non-pojos.

        Second - I've used JAXB2 to generate classes from very complex WSDL/XSD (Schengen Web Service) - after minor tweaks with *.jxb file everything worked like a charm!

        Third - JAXB2 is standard, is part of JEE 6, has Maven2 plugin and is really fast!

        Grzegorz Grzybek


        • #5
          Writing your own marshaller/unmarshaller implementations using XPath is also worth considering. It is more work up front but if done well will allow you to create a mapping that is less fragile in the face of change and so can save you effort in the long term if you are really doing loosely coupled SOA type web services.

          With regard to Castor I have encountered cases of incorrect behaviour when using multiple namespaces so my recommendation would be to avoid Castor where namespaces are used.

          Eclipse Moxy is also worth a look, MOXy, as a better implementation of JAXB.


          • #6
            Originally posted by JonasPartner View Post
            Eclipse Moxy is also worth a look, MOXy, as a better implementation of JAXB.
            I've never heard of MOXy before. Out of interest what makes it a better implementation of JAXB?


            • #7
              The main advantage is in giving greater flexibility both in the mapping and with regard to how you express your mapping. The one killer feature for me is the XPath support which allows you to use a programmatic API to build mappings as in the example below taken from the MOXy documentation.

              XMLDirectMapping firstNameMapping = new XMLDirectMapping();
              XMLDirectMapping lastNameMapping = new XMLDirectMapping();


              • #8
                Cool, I'm still trying to get my head into JAXB, been using Xstream with annotations and its so flipping fast to get it working, I'm struggling to see a reason to switch. I know JAXB is a standard but then, so it JSF and I HATE working with it. I think, at the end of the day its all about what makes sense to the wiring in your head, as we all dont think the same . One developers pain is another developers joy. Now thats a whole new subject. I'm actually going to be writing a thesis for my paper around this subject of, the IT professionals approach and thinking patterns to solving problems. ITS DAMN INTERESTING! But thats way OT!, so I'll refrain from further elaboration.....

                I will probably switch to JAXB once I got something basic working. Thanx for the tips guys, really appreciate it.


                • #9
                  Ok, I've been busy with JAXB however, I got a quick q...

                  We basically have a single incomming q with all sorts of messages coming in.
                  I pick up a message and discover the message type, then I need to
                  unmarshal the xml to pojo. Is it possible to have a unmarshaller that
                  will unmarshall different types of XML or is it better to have a
                  marshaller specific to its job based on the XML thats coming in?


                  • #10
                    You can follow either approach. If you plug-in a JAXB Marshaller, it can be used for mapping to/from multiple domain objects. I would probably base the decision on how closely related those domain objects are. Within Spring Integration, a pattern to consider would be: inbound WS endpoint -> jaxb-marshaller -> payload-type-router.



                    • #11
                      I second Mark, this worked pretty well for me too.

                      In some cases, one alternative to consider is using a service-activator using overloaded handler methods, but this only in the case when the processing of the different payload types can be grouped by some logical criterion, effectively allowing to use different types of Parameter Objects on the same service.