commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pete Ford (JIRA)" <j...@apache.org>
Subject [jira] Created: (BETWIXT-63) Writing Map key/value pairs produces incorrect XML tags
Date Fri, 29 Aug 2008 16:16:55 GMT
Writing Map key/value pairs produces incorrect XML tags
-------------------------------------------------------

                 Key: BETWIXT-63
                 URL: https://issues.apache.org/jira/browse/BETWIXT-63
             Project: Commons Betwixt
          Issue Type: Bug
         Environment: Windows XP, Java 1.6.0_04, Eclipse
            Reporter: Pete Ford
            Priority: Minor


Using download version 0.8.

A Map field within a Javabean produces XML containing Key and Value tags by default (i.e.
without a .betwixt file):

Java:

private Map<String, String> details = new TreeMap<String, String>();

Example XML output:

<Details>
  <entry>
    <Key>...</Key>
    <Value>...</Value>
  </entry>
</Details>

When reading the generated XML back into Betwixt to reconstruct the bean, the map is not populated.
It appears that when reading, Betwixt looks for the tags <key> and <value> (uncapitalized).
Filtering the XML to replace <Key> with <key>, etc., before reading in fixes the
problem. It would appear that Betwixt should be generating "<key>" and "<value>"
when writing (to match the case of the enclosing "<entry>" tag). Possibly this is something
to do with using Capitalized names (see the code below - it sets up a CapitalizedNamesMapper
for element names).

The code that configures the writer in this case is:

        StringWriter sw = new StringWriter();
        BeanWriter writer = new BeanWriter(sw);
        writer.getXMLIntrospector().getConfiguration()
                .setAttributesForPrimitives(true);
        writer.getXMLIntrospector().getConfiguration()
                .setWrapCollectionsInElement(true);
        writer.enablePrettyPrint();
        writer.getBindingConfiguration().setMapIDs(false);

        // set a custom name mapper for attributes
        writer.getXMLIntrospector().getConfiguration()
                .setAttributeNameMapper(new HyphenatedNameMapper());

        // set a custom name mapper for elements
        writer.getXMLIntrospector().getConfiguration()
                .setElementNameMapper(new CapitalizeNameMapper());


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message