Announcement Announcement Module
Collapse
No announcement yet.
simple castor marshalling example? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • simple castor marshalling example?

    Hello,
    It seems to me that I should be able to use the default mechanisms of castor to marshal a class to an xml stream using spring-ws, by calling (ex) this.marshaller.marshall(someObject, someStream)
    I've tried varies ways, but its not working yet. Am I right that this should be possible, and if so does anyone have an example that marshalls to a string?
    Thanks for the help

  • #2
    Bam.

    Code:
    StringWriter stringWriter = new StringWriter();
    Marshaller marshaller = new Marshaller(stringWriter);
    
    marshaller.marshal(myObject);
    
    String myXmlString = stringWriter.toString();

    Comment


    • #3
      Actually, that uses Castor's native API. If you want to use the OXM library, you might want to change that to:

      Code:
      StringWriter writer = new StringWriter();
      StreamResult result = new StreamResult(writer);
      
      marshaller.marshal(myObject, result);
      
      String xmlString = writer.toString();
      Cheers,

      Comment


      • #4
        thank you

        Excellent - thank you both for the help.
        ... Rich

        Comment


        • #5
          Arjen,

          What does marshaller belong to in this example?

          Comment


          • #6
            the thread is kinda old, but im sharing this for the benefit of people who also looked for it. this is a sample on using Spring OXM and Castor O/X Framework

            http://www.adobocode.com/spring/mars...ing-spring-oxm

            hope this helps others as well

            Comment

            Working...
            X