最近我一直在瀏覽此錯誤的stackoverflow,而且我幾乎無法找到所有線程上的解決方案去過。這就是爲什麼我在這裏發佈這個問題。未找到Java類型,類bookInfoListType和MIME媒體類型application/xml的消息正文編寫器
問題是我在回覆響應時說錯誤。這裏是我的XSD定義:
<xs:element name="bookInfoList">
<xs:complexType>
<xs:sequence>
<xs:element name="bookInfo" type="bookInfoType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="bookInfo" type="bookInfoType"/>
<xs:complexType name="bookInfoListType">
<xs:sequence>
<xs:element name="bookInfo" type="bookInfoType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="bookInfoType">
<xs:sequence>
<xs:element name="bookId" type="xs:string" minOccurs="1" maxOccurs="1"/>
<!-- ... more elements !-->
</xs:sequence>
</xs:complexType>
其生成以下bookListInfoType
類
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "bookInfoListType", propOrder = {
"bookInfo"
})
public class bookInfoListType {
protected List<bookInfoType> bookInfo;
public List<bookInfoType> getbookInfo() {
if (bookInfo == null) {
bookInfo = new ArrayList<bookInfoType>();
}
return this.bookInfo;
}
}
但是,當我嘗試將響應發送回像
return Response.status(HttpStatus.SC_OK).entity(bookInfoListConverter.convert(wsContext, allBooks)).build();
我得到的說錯誤。
在我ObjectFactory
,我確實看到
public bookInfoListType createbookInfoListType() {
return new bookInfoListType();
}
這裏是我的休息方法:
@Path ("v1/storename/")
public class BookResource
{
@GET
@Path ("books/{book_id}/info.xml")
@Produces (MediaType.APPLICATION_XML)
public Response getBookInfoXML() {
//business logic
return Response.status(HttpStatus.SC_OK).entity(bookInfoListConverter.convert(wsContext, allBooks)).build();
}
}
更何況,我已經生成的類另一個JAXB稱爲bookInfoList
,你可以在XSD見。他們的定義幾乎是一樣的(這是我懷疑的一件事,這可能是問題,但我遵循相同模式的其餘類都工作正常)。
我仍然試圖敲打我的腦袋想弄清楚發生了什麼事,但我沒有想法,任何幫助將不勝感激。
有什麼'clasNameListType'做這件事?什麼是錯誤,確切地說,以及堆棧跟蹤? – lexicore 2014-10-10 16:28:01
你可以發佈被調用來訪問你的服務(包括註釋)的方法嗎? – 2014-10-10 17:10:49
更新了我的問題並提供了所需的詳細信息 – 2014-10-10 17:34:40