This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bean is populated with null values while conversion of xml to bean

 
palakolanusrinu Reddy
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Please help any one in this while converting xml to bean, here I am using betwixt.This xml contains normal data as well as collections data but normal data and some of collection data is populating in beans and some collection data is populating beans with null values.

XML response is :
<?xml version="1.0" encoding="UTF-8"?>
<Hostel noOfHostels="1">
<HostelRoom
roomNo="0004105232" roomLocation="2101086158" roomPlace="2622" bookedOn="08/27/2008 03:07:56 PM"
roomName="TAMIL NADU" quota="GN" class="SL" source="ndls" destination="mas"
day="28" month="08" year="2008" bordingdate="08/28/2008 12:00:00 AM"
internetServiceCharge="20.00" roomFare="2696.00" totalFare="2716.00" idPassenger="1">

<Passenger slNo="1" name="TEST" age="35" sex="m" concessionCode="BLANK" bookingStatus="RLWL 6" />
<Passenger slNo="2" name="aaaa" age="85" sex="m" concessionCode="NOCONC" bookingStatus="RLWL 7" />

</HostelRoom>
</Hostel>

and betwixt mapping is
MAPPING = new String(
"<?xml version=\"1.0\"?>"
+ "<betwixt-config>"
+ "<!--name of the class to map -->"
+ "<class com.booking.BookingSearchResponse\">"
+ "<element name=\"Hostel\">"
+ "<attribute name=\"noOfHostels\" property=\"noOfHostels\"/>"
//+ "<element name=\"HostelRoom\">"
+ "<element name=\"HostelRoom\" property=\"hostelRoom\" updater=\"addHostelRoom\" class=\"com.booking.BookedTicket\"/>"
+ "</element>"
+ "</class>"
+ "<class name=\"com.booking.BookedTicket\">"
+ "<element name=\"HostelRoom\">"
+ "<attribute name=\"roomNo\" property=\"roomNo\"/>"
+ "<attribute name=\"roomLocation\" property=\"roomLocation\"/>"
+ "<attribute name=\"quota\" property=\"quota\"/>"
-----
------
+ "</element>"
+ "<element name=\"Passenger\">"
+ "<element name=\"Passenger\" property=\"passenger\" updater=\"addPassenger\" class=\"com.booking.BookedPassenger\"/>"
+ "</element>"
+ "</class>"
+ "<class name=\"com.booking.BookedPassenger\">"
+ "<element name=\"Passenger\">"
+ "<attribute name=\"slNo\" property=\"slNo\"/>"
+ "<attribute name=\"name\" property=\"name\"/>"
+ "<attribute name=\"age\" property=\"age\"/>"
+ "<attribute name=\"sex\" property=\"sex\"/>"
+ "<attribute name=\"concessioncode\" property=\"concessionCode\"/>"
+ "<attribute name=\"bookingstatus\" property=\"bookingStatus\"/>"

+ "</element>" + "</class>"
+ "</betwixt-config>");

and i created 3 POJOs

1)BookingSearchResponse.java
2)BookedTicket.java
3)BookedPassenger.java

BookingSearchResponse.java
//included updater
public void addHostelRoom(BookedTicket bookedTicket) {
(this is arrayList)hostelRoom.add(bookedTicket);
}

BookedTicket.java
public void addPassenger(BookedPassenger passenger){
(this is arrayList)passenger.add(passenger);


}
Here noOfHostels and passenger collection is populating properly but HostelRoom collection is not populating please help in this

to parse this we used

public static Object xmlToBean(Object object, String xml)throws Exception{
BeanReader beanReader = null ;
try {
beanReader = new BeanReader();
//Set the ConvertUtils Object for String Conversion of the Default primitive classes
beanReader.getBindingConfiguration()
.setObjectStringConverter(new ObjectStringConverter());

beanReader.getBindingConfiguration().setValueSuppressionStrategy(new AttributeValueSuppressionStrategy());
String temp = (String)object.getClass().getField("MAPPING").get(object);
beanReader.registerMultiMapping(new InputSource(new StringReader(temp)));

Object parsedObject = beanReader.parse(new StringReader(xml));

return parsedObject;

}

Regards,
Srinivasa Reddy.P
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic