• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Castor unable to Map - please help

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi i am using castor to bind java object to xml. I am using mapping file so that i can change the tag name but the tag name don't change.

Java code
try
{
System.out.println(datarecord);
InputStream inputstream = getResourceAsStream("gen_mapping.xml");
System.out.println("InputStream ::::::::: " + inputstream);
Mapping mapping = new Mapping(this.getClass().getClassLoader());
mapping.loadMapping(new InputSource(inputstream));
System.out.println("Mapping ::::::::: " + mapping);

StringWriter writer = new StringWriter();
Marshaller marshal = new Marshaller(writer);
marshal.setMapping(mapping);
Marshaller.marshal(datarecord, writer);
xmlStr = writer.getBuffer().toString();
System.out.println(xmlStr);
//callsessionbean(xmlStr);
}
catch(Exception e)
{
xmlStr = "Inside the exception of Castor Mapping";
System.out.println(xmlStr);
e.printStackTrace();
}

Mapping file
<?xml version="1.0" encoding="UTF-8"?>
<mapping>

<description>Castor generated mapping file</description>
<class name="uk.co.capgemini.www.ChildServiceProvider">
<description>Default mapping for class uk.co.capgemini.www.ChildServiceProvider</description>
<map-to xml="child-service-provider"/>
<field name="name" type="java.lang.String">
<bind-xml name="name" node="element"/>
</field>
<field name="phoneDetails" type="uk.gov.govtalk.www.TelephoneStructure">
<bind-xml name="phone-details" node="element"/>
</field>
</class>
<class name="uk.co.capgemini.www.ChildDemographics">
<description>Default mapping for class uk.co.capgemini.www.ChildDemographics</description>
<map-to xml="child-demographics"/>
<field name="childName" type="uk.co.capgemini.www.IndexPersonName">
<bind-xml name="child-name" node="element"/>
</field>
</class>
<class name="uk.co.capgemini.www.MatchRecord">
<description>Default mapping for class uk.co.capgemini.www.MatchRecord</description>
<map-to xml="match-record"/>
<field name="coreChildDetails" type="uk.co.capgemini.www.ChildDemographics" collection="array">
<bind-xml name="core-child-details" node="element"/>
</field>
<field name="childID" type="uk.co.capgemini.www.ChildId">
<bind-xml name="ChildID" node="element"/>
</field>
<field name="serviceHistory" type="uk.co.capgemini.www.ChildServiceProvision" collection="array">
<bind-xml name="service-history" node="element"/>
</field>
</class>
<class name="uk.gov.govtalk.www.TelephoneStructure">
<description>Default mapping for class uk.gov.govtalk.www.TelephoneStructure</description>
<map-to xml="telephone-structure"/>
<field name="telExtensionNumber" type="java.lang.String">
<bind-xml name="tel-extension-number" node="element"/>
</field>
<field name="telNationalNumber" type="java.lang.String">
<bind-xml name="tel-national-number" node="element"/>
</field>
<field name="telCountryCode" type="java.lang.String">
<bind-xml name="tel-country-code" node="element"/>
</field>
</class>
<class name="uk.co.capgemini.www.ChildServiceProvision">
<description>Default mapping for class uk.co.capgemini.www.ChildServiceProvision</description>
<map-to xml="child-service-provision"/>
<field name="sensitive" type="boolean">
<bind-xml name="sensitive" node="attribute"/>
</field>
<field name="childProvisionID" type="java.lang.Integer">
<bind-xml name="child-provision-iD" node="element"/>
</field>
<field name="type" type="java.lang.String">
<bind-xml name="type" node="element"/>
</field>
<field name="provider" type="uk.co.capgemini.www.ChildServiceProvider">
<bind-xml name="provider" node="element"/>
</field>
</class>
<class name="uk.co.capgemini.www.ChildId">
<description>Default mapping for class uk.co.capgemini.www.ChildId</description>
<map-to xml="ChildID"/>
<field name="Type" type="java.lang.String">
<bind-xml name="Type" node="element"/>
</field>
<field name="Value" type="java.lang.String">
<bind-xml name="Value" node="element"/>
</field>
<field name="Format" type="java.lang.String">
<bind-xml name="Format" node="element"/>
</field>
</class>
<class name="uk.co.capgemini.www.IndexPersonName">
<description>Default mapping for class uk.co.capgemini.www.IndexPersonName</description>
<map-to xml="index-person-name"/>
<field name="familyName" type="java.lang.String">
<bind-xml name="family-name" node="element"/>
</field>
<field name="nameStatus" type="java.lang.Object">
<bind-xml name="name-status" node="element"/>
</field>
<field name="givenName3" type="java.lang.String">
<bind-xml name="given-name3" node="element"/>
</field>
<field name="givenName2" type="java.lang.String">
<bind-xml name="given-name2" node="element"/>
</field>
<field name="givenName1" type="java.lang.String">
<bind-xml name="given-name1" node="element"/>
</field>
<field name="title" type="java.lang.String">
<bind-xml name="title" node="element"/>
</field>
</class>
</mapping>

output string
<?xml version="1.0" encoding="UTF-8"?>
<match-record><core-child-details><child-name><family-name>Kirby</family-name><given-name3>Willy</given-name3><given-name2>Bill</given-name2><given-name1>William</given-name1></child-name></core-child-details><child-iD><type>String</type><value>NHS</value><format>NHS_1</format></child-iD><service-history sensitive="true"><child-provision-iD>1</child-provision-iD><type>Health Check</type><provider><name>NSPCC</name><phone-details><tel-extension-number></tel-extension-number><tel-national-number></tel-national-number><tel-country-code></tel-country-code></phone-details></provider></service-history></match-record>

the child-id remains the same and does not get updated to ChildID.
Please help me out.
 
Hey! Wanna see my flashlight? It looks like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic