我无法让JAXB在Resteasy JAX-RS服务器应用程序中解组时间戳.
我的班级看起来像这样:
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "foo")
public final class Foo {
// Other fields omitted
@XmlElement(name = "timestamp", required = true)
protected Date timestamp;
public Foo() {}
public Date getTimestamp() {
return timestamp;
}
public String getTimestampAsString() {
return (timestamp != null) ? new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timestamp) : null;
}
public void setTimestamp(final Date timestamp) {
this.timestamp = timestamp;
}
public void setTimestamp(final String timestampAsString) {
try {
this.timestamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(timestampAsString);
} catch (ParseException ex) {
this.timestamp = …Run Code Online (Sandbox Code Playgroud) 我们有一个 xml 文件,需要对其进行解组(转换为 Java 对象)。现在 Java 对象是第三方的,我无法对其进行注释以进行解组。关于如何在没有注释的情况下解组的任何想法。请在下面找到我的代码片段
JAXBContext context;
try {
context = JAXBContext.newInstance(Abc.class);
Unmarshaller unMarshaller = context.createUnmarshaller();
Abc abc= (Abc) unMarshaller.unmarshal(new FileInputStream("C:\\Documents and Settings\\sandeep.nair\\Desktop\\abc.xml"));
} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (Exception e){
}
Run Code Online (Sandbox Code Playgroud)
我收到以下异常。一个用于无参数构造函数(我知道我可以通过为适配器添加注释来解决这个问题,但我想知道或查看一个在没有注释的情况下处理它的示例片段)
同样,我收到另一条关于 JAXB 无法处理接口的消息。
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:5 个 IllegalAnnotationExceptions java.sql.Timestamp 没有无参数默认构造函数。此问题与以下位置有关: 在 java.sql.Timestamp 在 public java.sql.Timestamp com.test.Abc.getSomeTimestamp() 在 com.riteaid.entities.customer.Customer com.test.Def 没有无参数默认构造函数。此问题与以下位置有关:at com.test.Def...
java.sql.Date 没有无参数默认构造函数。这个问题与以下位置有关:at java.sql.Date ... com.test.Ghi 是一个接口,JAXB 无法处理接口。此问题与以下位置有关: ... com.test.Ghi 没有无参数默认构造函数。这个问题与以下位置有关:..