You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Pete Ford (JIRA)" <ji...@apache.org> on 2008/08/29 18:26:44 UTC
[jira] Updated: (BETWIXT-63) Writing Map key/value pairs produces
incorrect XML tags
[ https://issues.apache.org/jira/browse/BETWIXT-63?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Pete Ford updated BETWIXT-63:
-----------------------------
Description:
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());
[EDIT:]
Tested the above code changing it so that it uses DecapitalizeNameMapper and also HyphenatedNameMapper for the element names. In both cases the key/value tags are rendered lowercase and behave correctly on readback.
was:
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());
> 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());
> [EDIT:]
> Tested the above code changing it so that it uses DecapitalizeNameMapper and also HyphenatedNameMapper for the element names. In both cases the key/value tags are rendered lowercase and behave correctly on readback.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.