Announcement Announcement Module
No announcement yet.
CastorMarshaller for multiple classes Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • CastorMarshaller for multiple classes

    Hi all,
    I'm trying to use the new oxm Marshal/Unmarshal functions built in spring, but with little success so far

    Using castor's SourceGenerator, I generated a lot of stubs for a schema file. What I want to do is to marshal the stubs to XML and unmarshal the XML back to the original stubs. In order to do this, I created a castorMarshaller bean (similarly as described here )

    <bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarsha ller">
    <property name="validating" value="false"/>
    <property name="targetClass">
    <value type="java.lang.Class">mypkg.myclass</value>

    and I tried to use it in my code. This approach works fine when I want to unmarshal just one class, but fails to work properly for more classes.

    Would it be possible to use just one castormarshaller bean to unmarshal different class types? Or should I instantiate more beans, each one with a different targetClass? I read it's possible to use a castorMapping.xml, but I could not find any useful example... ?!?

    Last point: for some reasons, when unmarshalling, the framework validates the input xml files even when the castorMarshaller's validation property is set to "false". Any hints? Could this be a bug?

    Thanks a lot for your comments

  • #2
    You will need to use a mapping file for marshalling multiple classes. Help is provided here.

    Regarding the validation: some marshallers do "some", to make sure that the XML can actually be transformed into the object (or vice-versa). This type of validation is not very strict, though...


    • #3
      Hi Arjen,
      thanks for the info, but I already knew the official castor help page. Their page did not help me since my classes (generated automatically from the xsd file) already know how to "unmarshal". The problem is not "how to unmarshal one class", rather "which class has to be unmarshalled"...

      In my second point, maybe I was not clear. Castor validates my input XML files even when I say to not do it. For example, castor fails to unmarshal an XML that does not contain all the mandatory fields... (I think that without validation it should unmarshal all the available fields, without complaining about the missing ones).

      Thanks again