[英]JAXB annotation RootElement
I have the following POJO , and the root element is not showing in the xml file (send over SOAP jax-ws call), can people point out the problem please? 我有以下POJO,并且xml文件中没有显示根元素(通过SOAP jax-ws调用发送),人们可以指出这个问题吗?
@XmlRootElement(name = "CATALOGUE")
@XmlAccessorType( XmlAccessType.FIELD )
public class Catalogue implements Serializable, Comparable<Catalogue>
{
@XmlTransient
private Integer catalogueId;
@XmlElement( name = "COMMENT", required = false, nillable = false )
private String catalogueComment;
@XmlElement( name = "VERSION", required = false, nillable = false )
private String catalogueVersion;
@XmlElement( name = "VALID_FROM_DTS", required = false, nillable = false )
private Date catalogueValidFromDts;
@XmlElement( name = "CREATED_DTS", required = false, nillable = false )
private Date catalogueCreatedDts;
@XmlElementWrapper(name = "ITEMLIST")
@XmlElement(name = "ITEM")
private List<Item> itemList;
@XmlTransient
private Integer catalogueLifecyclePhase;
@XmlTransient
private Integer ownerId;
the xml file looks like xml文件看起来像
<COMMENT>LK</COMMENT>
<VERSION>4</VERSION>
<VALID_FROM_DTS>1990-01-25T00:00:00Z</VALID_FROM_DTS>
<CREATED_DTS>2012-05-14T15:49:38.655+01:00</CREATED_DTS>
<ITEMLIST>
<ITEM>
<NAME>Adult Period Pass Corsham</NAME>
<DESC>1 week</DESC>
<SKU>ACT-38</SKU>
<PRICE>15</PRICE>
<CATEGORIES>
<CATEGORY>
<CategoryName>Product</CategoryName>
<CategoryDate>1 week</CategoryDate>
<CategorySortOrder>0</CategorySortOrder>
</CATEGORY>
<CATEGORY>
<CategoryName>Product Type</CategoryName>
<CategoryDate>Coach</CategoryDate>
<CategorySortOrder>0</CategorySortOrder>
</CATEGORY>
.....................
i would expecting something like 我希望有类似的东西
<CATALOGUE> <-----------missing!!!
<COMMENT>LK</COMMENT>
<VERSION>4</VERSION>
<VALID_FROM_DTS>1990-01-25T00:00:00Z</VALID_FROM_DTS>
<CREATED_DTS>2012-05-14T15:49:38.655+01:00</CREATED_DTS>
<ITEMLIST>
<ITEM>
<NAME>Adult Period Pass Corsham</NAME>
<DESC>1 week</DESC>
<SKU>ACT-38</SKU>
<PRICE>15</PRICE>
<CATEGORIES>
<CATEGORY>
<CategoryName>Product</CategoryName>
<CategoryDate>1 week</CategoryDate>
<CategorySortOrder>0</CategorySortOrder>
</CATEGORY>
<CATEGORY>
<CategoryName>Product Type</CategoryName>
<CategoryDate>Coach</CategoryDate>
<CategorySortOrder>0</CategorySortOrder>
</CATEGORY>
.....................
</CATALOGUE>
The Code used to Return the Object is 用于返回对象的代码是
@Stateless
@Remote
@WebService
public class CatalogueManagerSoapService
{
public CatalogueManagerSoapService()
{
// TODO Auto-generated constructor stub
}
@EJB
private SOAPExportService userService;
@WebMethod
public Catalogue getLatestCatalogue(
String username,
String password,
String catalogueName ) throws Exception
{
Catalogue c = CatManager.getCatalogue();
return c;
}
}
Answer my Own question 回答我自己的问题
this is what the JAX-WS (JRS181) default implementation for @WebResult 这是@WebResult的JAX-WS(JRS181)默认实现
@Retention(value=RetentionPolicy.RUNTIME)
@Target({METHOD})
public @interface WebResult {
String name() default "return";
String targetNamespace() default "";
boolean header() default false;
String partName() default "";
}
as you can see "return" is by default. 如您所见,默认情况下是“返回”。 change to @WebResult( name = "CATALOGUE") solved the problem
更改为@WebResult(name =“ CATALOGUE”)解决了该问题
I think that you need a package-info.java file, try something like this: 我认为您需要package-info.java文件,请尝试如下操作:
@XmlSchema(namespace = "<your namespace>",
xmlns = @XmlNs(prefix = "<your prefix>", namespaceURI = "<your namespace>"),
elementFormDefault = XmlNsForm.QUALIFIED
)
@XmlAccessorType(XmlAccessType.NONE)
@XmlAccessorOrder(XmlAccessOrder.UNDEFINED)
package your.package.name;
import javax.xml.bind.annotation.XmlAccessOrder;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorOrder;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;
just put it in the root of your package, edit as needed and generate the xsd again. 只需将其放在包的根目录中,根据需要进行编辑,然后再次生成xsd。 Should be ok.
应该可以。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.