gpt4 book ai didi

java - Jersey UnmarshalException JAXB,带有多个 getEntity() 的 XML

转载 作者:行者123 更新时间:2023-12-04 05:41:39 28 4
gpt4 key购买 nike

我有这个异常(exception)。

我的对象看起来像这样:

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class ObjectDTO implements Serializable {

/**
*
*/
private static final long serialVersionUID = -8545841080597549468L;

@XmlElement(name="objectId")
private String objectId;
@XmlElement(name="owner")
private String owner;
@XmlElement(name="objectName")
private String objectName;

Constructor, getter/setter, toString, Hash...

现在我调用我的服务方法:
 ClientResponse postRes = service.path("rest").path("object").accept(MediaType.APPLICATION_XML).post(ClientResponse.class, object);

当我做
 System.out.println(postRes.getEntity(ObjectDTO.class));

它工作正常。但是当我尝试对我的对象执行 get 操作时,例如:
 String string = postRes.getEntity(ObjectDTO.class).getObjectId();

我得到了异常(exception)。
 javax.ws.rs.WebApplicationException: javax.xml.bind.UnmarshalException - with linked exception: [org.xml.sax.SAXParseException: Premature end of life.]  

怎么了?

最佳答案

看起来您正在尝试读取实体两次(第二次实体流已被消耗)。与其调用 postRes.getEntity() 两次,不如只调用一次,将结果存储在一个变量中,然后对该变量进行操作。

关于java - Jersey UnmarshalException JAXB,带有多个 getEntity() 的 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11194027/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com