Reputation: 6620
I defined all required elements but the code can not parse server response. I changed @XmlSeeAlso({ Artist.class, Venue.class })
to @XmlSeeAlso({Venue.class })
but it did not help.
I also added a package-info.java
file.
@XmlSchema(
namespace = "http://ticketmaster.productserve.com/v2/soap.php",
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED
)
package com.myproject.tickets.ticketmaster;
import javax.xml.bind.annotation.*;
Error
org.springframework.http.converter.HttpMessageNotReadableException: Could not
unmarshal to [class com.myproject.tickets.ticketmaster.Data]: unexpected
element (uri:"", local:"data"). Expected elements are
<{http://ticketmaster.productserve.com/v2/soap.php}artist>,
<{http://ticketmaster.productserve.com/v2/soap.php}data>,
<{http://ticketmaster.productserve.com/v2/soap.php}details>,
<{http://ticketmaster.productserve.com/v2/soap.php}results>,
<{http://ticketmaster.productserve.com/v2/soap.php}venue>; nested exception
is javax.xml.bind.UnmarshalException: unexpected element (uri:"",
local:"data"). Expected elements are
<{http://ticketmaster.productserve.com/v2/soap.php}artist>,
<{http://ticketmaster.productserve.com/v2/soap.php}data>,
<{http://ticketmaster.productserve.com/v2/soap.php}details>,
<{http://ticketmaster.productserve.com/v2/soap.php}results>,
<{http://ticketmaster.productserve.com/v2/soap.php}venue>
Response
<?xml version="1.0"?>
<data>
<details>
<totalResults></totalResults>
<totalPages></totalPages>
<currentPage></currentPage>
<resultsPerPage></resultsPerPage>
</details>
<results>
<eventId></eventId>
<ticketmasterEventId></ticketmasterEventId>
<status></status>
<name></name>
<url></url>
<eventDate></eventDate>
<onSaleDate></onSaleDate>
<preSaleDate></preSaleDate>
<category></category>
<categoryId></categoryId>
<parentCategory></parentCategory>
<parentCategoryId></parentCategoryId>
<minPrice></minPrice>
<maxPrice></maxPrice>
<artists>
<artistId></artistId>
<ticketmasterArtistId></ticketmasterArtistId>
<name></name>
<url></url>
<imageUrl></imageUrl>
<category></category>
<categoryId></categoryId>
<parentCategory></parentCategory>
<parentCategoryId></parentCategoryId>
</artists>
<venue>
<venueId></venueId>
<ticketmasterVenueId></ticketmasterVenueId>
<name></name>
<street></street>
<city></city>
<country></country>
<postcode></postcode>
<url></url>
<imageUrl></imageUrl>
<state/>
</venue>
</results>`
<results>
.....
</results>
</data>
Data
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Data {
@XmlElement
Details details;
@XmlElement
List<Results> results;
public Data() {
super();
this.results = new ArrayList<Results>();
}
Details
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Details {
@XmlElement
private int totalResults;
@XmlElement
private int totalPages;
@XmlElement
private int currentPage;
@XmlElement
private int resultsPerPage;
Results
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlSeeAlso({ Artist.class, Venue.class })
public class Results {
@XmlElement
private long eventId;
@XmlElement
private String ticketmasterEventId;
@XmlElement
private String status;
@XmlElement
private String name;
@XmlElement
private String url;
@XmlElement
private String eventDate;
@XmlElement
private String onSaleDate;
@XmlElement
private String preSaleDate;
@XmlElement
private int categoyId;
@XmlElement
private String parentCategory;
@XmlElement
private int parentCategoryId;
@XmlElement
private Double minPrice;
@XmlElement
private Double maxPrice;
@XmlElement(name = "Artists")
private List<Artist> artists;
@XmlElement
private Venue venue;
public Results() {
super();
this.artists = new ArrayList<Artist>();
}
Artist
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Artist {
@XmlElement
private long artistId;
@XmlElement
private long ticketMasterArtistId;
@XmlElement
private String name;
@XmlElement
private String url;
@XmlElement
private String imageUrl;
@XmlElement
private String category;
@XmlElement
private int categoryId;
@XmlElement
private String parentCategory;
@XmlElement
private int parentCategoryId;
Upvotes: 0
Views: 2785
Reputation: 1067
Your problem is that your unmarshaller expect an element with a namespace, while your XML doesn't have any.
For solving your problem, either :
Put a namespace in your XML (xmlns="http://ticketmaster.productserve.com/v2/soap.php" attribute in your root element)
Remove the namespace attribute from your @XmlSchema annotation
Upvotes: 1