0
JAXBについて読んだことがあります。 MessageResposne次のXMLのためのjaxb注釈
@XmlRootElement
class MessageResponse extends Response {
String message;
public MessageResponse() {
// TODO Auto-generated constructor stub
}
public MessageResponse(String command, String message) {
super(command);
this.message = message;
}
@XmlElement
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
とメインクラスで
:レスポンス@XmlRootElement
abstract class Response {
String command;
public Response() {
// TODO Auto-generated constructor stub
}
public Response(String command) {
this.command = command;
}
@XmlElement
public String getCommand() {
return command;
}
public void setCommand(String command) {
this.command = command;
}
}
子クラス - 私はここで
<response>
<command></command>
<message></message>
</response>
は、私のクラスは
抽象親クラスで私のクラスから次のXMLをしたいです
try {
objContext = JAXBContext.newInstance(Response.class);
objMarshaller = objContext.createMarshaller();
} catch (JAXBException e) {
e.printStackTrace();
}
が、これは、私が希望resposne
エラーを表示しています:[致命的なエラー]:1:56:ファイルの早すぎる終了。 のjava.lang.NullPointerException –
私はクラスをMessageResponseする@XmlRootElementを追加し、 messageResponse> –
この生成され SETNAME 私のメッセージは、これはよさそうです。最後に欠けているのは、XmlRootElementの 'name'属性です。私は答えを編集しました。 –