commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Carter Bradford" <>
Subject [Betwixt] How to flatten the object structure when serializing to XML
Date Thu, 29 May 2008 22:38:24 GMT

I have the following simple problem:

I have an object structure as follows:

public class Person {
  private String name;
  private int age;
  private Address addr;

  <...Standard Getters and Setters..>

public class Address {
  private String addrLine1;
  private String city;
  private String state;

<...Standard Getters and Setters...>


I want to map this into a a flat XML structure as follow:


In other words, I don't want the Address wrapped in its own element.  I have
a mapping file as follows:

<?xml version="1.0" encoding="UTF-8" ?>
    <class name="Person">
        <element name="Person">
            <element name="Name" property="name"/>
            <element name="Age" property="age"/>
            <element name="Address" property="address"/>
     <class name="">
        <element name="Address">
            <element name="AddrLine1" property="addrLine1"/>
            <element name="City" property="city"/>
            <element name="State" property="state"/>

I want to suppress the surrounding "Address" element.  This should be easy,
but it's not obvious to me.  Any help would be much appreciated.



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message