import javax.xml.bind.*;
import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.*;
import java.io.*;
import java.util.*;

@XmlRootElement(name="myroot")
@XmlAccessorType(XmlAccessType.NONE)
class SO19509130a {

    private String id;
    private Properties props = new Properties();

    @XmlAttribute public String getId() { return id; }
    public void setId(String id) { this.id = id; }

    @XmlElement
    @XmlJavaTypeAdapter(SO19509130a.PropertiesAdapter.class)
    public Properties getProperties() { return props; }
    public void setProperties(Properties props) { this.props.putAll(props); }

    @XmlType(name="property") static class XmlProperty {
        @XmlAttribute public String key;
        @XmlValue public String value;
    }

    @XmlType(name="properties") static class XmlProperties {
        @XmlElement(name="entry") public Collection<XmlProperty> entries
            = new ArrayList<XmlProperty>();
    }

    static class PropertiesAdapter
        extends XmlAdapter<XmlProperties, Properties>
    {
        public XmlProperties marshal(Properties props) {
            XmlProperties xml = new XmlProperties();
            for (Map.Entry<Object, Object> entry: props.entrySet()) {
                XmlProperty xmlEntry = new XmlProperty();
                xmlEntry.key = entry.getKey().toString();
                xmlEntry.value = entry.getValue().toString();
                xml.entries.add(xmlEntry);
            }
            return xml;
        }
        public Properties unmarshal(XmlProperties xml) {
            Properties props = new Properties();
            for (XmlProperty entry: xml.entries)
                props.setProperty(entry.key, entry.value);
            return props;
        }
    }

    public static void main(String[] args) throws Exception {
        SO19509130a obj = new SO19509130a();
        obj.id = "theID";
        obj.props.setProperty("key1", "val1");
        obj.props.setProperty("key2", "val2");
        JAXBContext ctx = JAXBContext.newInstance(SO19509130a.class);
        Marshaller m = ctx.createMarshaller();
        Unmarshaller u = ctx.createUnmarshaller();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        m.marshal(obj, baos);
        InputStream bais = new ByteArrayInputStream(baos.toByteArray());
        obj = (SO19509130a)u.unmarshal(bais);
        m.marshal(obj, System.out);
        System.out.println();
    }
}
