I want to convert context of xml file to java object.
But some part is extracted ok, and some has null values.
Here is xml file:
<OTA_AirLowFareSearchRQ EchoToken="50987" SequenceNmbr="1" Target="Production" TimeStamp="2003-11-19T19:44:10-05:00"
Version="2.001"
xsi:schemaLocation="http://ift.tt/NpIDks OTA_AirLowFareSearchRQ.xsd"
xmlns:xsi="http://ift.tt/ra1lAU"
xmlns="http://ift.tt/NpIDks">
<POS>
<TPA_Extensions>
<TPA_Extension>
<PromoRatesRequired Value="false"/>
<UserName Value="342561"/>
<UserPassword Value="1234"/>
<ClearCache Value="true"/>
</TPA_Extension>
</TPA_Extensions>
</POS>
<OriginDestinationInformation>
<DepartureDateTime>2015-04-13T00:00:00</DepartureDateTime>
<OriginLocation LocationCode="DUB"/>
<DestinationLocation LocationCode="CDG"/>
</OriginDestinationInformation>
<TravelPreferences>
<CabinPref PreferLevel="Preferred" Cabin="Economy"/>
</TravelPreferences>
<TravelerInfoSummary>
<AirTravelerAvail>
<PassengerTypeQuantity Code="ADT" Quantity="1"/>
<PassengerTypeQuantity Code="CHD" Quantity="0"/>
<PassengerTypeQuantity Code="INF" Quantity="1"/>
</AirTravelerAvail>
</TravelerInfoSummary>
</OTA_AirLowFareSearchRQ>
I have trouble with extracting 'OriginDestinationInformation' and 'AirTravelerAvail'.
Here is main() :
public static void main(String[] args) {
try {
JAXBContext context = JAXBContext.newInstance(OTAAirLowFareSearchRQ.class);
Unmarshaller um = context.createUnmarshaller();
OTAAirLowFareSearchRQ rq = (OTAAirLowFareSearchRQ) um.unmarshal(new FileReader(FILE_NAME));
System.out.println(rq);
} catch (FileNotFoundException | JAXBException e) {
LOGGER.error(e);
}
}
Here is output snippet:
originDestinationInformation=[OriginDestinationInformation{
departureDateTime=null,
originLocation=null,
destinationLocation=null,
alternateLocationInfo=null,
rph='null',
refNumber=null}],
travelerInfoSummary=TravelerInfoSummary{
ticketingCountryCode='null',
specificPTCIndicator=null,
airTravelerAvails=null},
echoToken='50987',
timeStamp=2003-11-19T19:44:10-05:00,
target='Production',
version=2.001,
transactionIdentifier='null',
sequenceNmbr=1,
And much more interesting part 'OriginDestinationInformation'Ж
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "OriginDestinationInformation", propOrder = {
"departureDateTime",
"originLocation",
"destinationLocation",
"tpaExtensions",
"alternateLocationInfo",
"rph",
"refNumber"
})
public static class OriginDestinationInformation extends OriginDestinationInformationType {
@XmlElement(name = "DepartureDateTime", required = true)
protected TimeInstantType departureDateTime;
@XmlElement(name = "OriginLocation", required = true)
protected OriginLocation originLocation;
@XmlElement(name = "DestinationLocation", required = true)
protected DestinationLocation destinationLocation;
@Transient
@XmlElement(name = "AlternateLocationInfo")
protected AlternateLocationInfo alternateLocationInfo;
@XmlElement(name = "TPA_Extensions")
protected TPAExtensionsType tpaExtensions;
@XmlAttribute(name = "RPH")
protected String rph;
@XmlAttribute(name = "RefNumber")
protected Integer refNumber;
// getters and setters
'TimeInstantType':
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "TimeInstantType", propOrder = {
"value"
})
public class TimeInstantType {
@Property("dateTime")
@XmlValue
protected String value;
// rest of class
'OriginLocation':
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "OriginLocation")
public static class OriginLocation extends LocationType {
@XmlAttribute(name = "MultiAirportCityInd")
protected Boolean multiAirportCityInd;
@XmlAttribute(name = "AlternateLocationInd")
protected Boolean alternateLocationInd;
@XmlAttribute(name = "LocationCode")
protected String locationCode;
DestinationLocation:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "DestinationLocation")
public static class DestinationLocation extends LocationType {
@XmlAttribute(name = "MultiAirportCityInd")
protected Boolean multiAirportCityInd;
@XmlAttribute(name = "AlternateLocationInd")
protected Boolean alternateLocationInd;
@XmlAttribute(name = "LocationCode")
protected String locationCode;
and for TravelerInfoSummary
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "TravelerInfoSummary", propOrder = {
"airTravelerAvails",
"ticketingCountryCode",
"specificPTCIndicator"
})
public static class TravelerInfoSummary extends TravelerInfoSummaryType {
@Embedded
@XmlElement(name = "AirTravelerAvail")
protected List<AirTravelerAvail> airTravelerAvails;
AirTravelerAvail:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "AirTravelerAvail")
public class AirTravelerAvail {
@Embedded
@XmlElement(name = "PassengerTypeQuantity")
@XmlElementWrapper(name = "AirTravelerAvail")
protected List<PassengerTypeQuantity> passengerTypeQuantities;
I couldn't figure out what is wrong here. I tried
@XmlElementWrapper(name = "AirTravelerAvail")
for list of objects but it keep getting null.
How to solve this trouble?
No comments:
Post a Comment