0
I tried to unmarshall following xml file.
<ns2:Triggermessage xmlns="http://www.asd.com/messaging" xmlns:ns2="http://www.asd.com/messaging/closing/trigger">
<Header>
<creationTimeStamp>2017-05-23T12:11:46.950+00:00</creationTimeStamp>
<businessDate>2017-05-23</businessDate>
<messageId>20170523-22:30:00_Calypso Rpt 7_444_0</messageId>
<conversationId>7397dbd3-5177-40ff-acb5-1b2ba8d0d1f6</conversationId>
<numberOfRecords>1</numberOfRecords>
<sentBy>ABCDE</sentBy>
<sendto>Camplico</sendto>
<processingCycle>ACD</processingCycle>
</Header>
<ns2:Request>
<ns2:ProcessingCircle>EOD</ns2:ProcessingCircle>
</ns2:Request>
</ns2:Triggermessage>
Here I created classes in this way.(not all the classes are mentioned here)
**TriggerMessage.java**
@XmlRootElement(name = "TriggerMessage", namespace="http://www.asd.com/messaging/closing/trigger")
public class TriggerMessage {
private Header header;
private Request request;
@XmlElement(name = "Header")
public Header getHeader() {
return header;
}
public void setHeader(Header header) {
this.header = header;
}
@XmlElement(name = "Request")
public Request getRequest() {
return request;
}
public void setRequest(Request request) {
this.request = request;
}
}
**Header.java**
private CreationTimeStamp creationTimeStamp;
private BusinessDate businessDate;
private MessageId messageId;
private ConversationId conversationId;
private SentBy sentBy;
private SendTo sendTo;
private ProcessingCycle processingCycle;
private NumberOfRecords numberOfRecords;
@XmlElement(name = "creationTimeStamp")
public CreationTimeStamp getCreationTimeStamp() {
return creationTimeStamp;
}
public void setCreationTimeStamp(CreationTimeStamp creationTimeStamp) {
this.creationTimeStamp = creationTimeStamp;
}
@XmlElement(name = "businessDate")
public BusinessDate getBusinessDate() {
return businessDate;
}
public void setBusinessDate(BusinessDate businessDate) {
this.businessDate = businessDate;
}
@XmlElement(name = "conversationId")
public ConversationId getConversationId() {
return conversationId;
}
public void setConversationId(ConversationId conversationId) {
this.conversationId = conversationId;
}
@XmlElement(name = "messageId")
public MessageId getMessageId() {
return messageId;
}
public void setMessageId(MessageId messageId) {
this.messageId = messageId;
}
-
-
-}
**CreationTimeStamp.java**
public class CreationTimeStamp {
private String value;
@XmlMixed
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
**Request.java**
@XmlType(namespace="http://www.asd.com/messaging/closing/trigger")
public class Request {
private ProcessingCircle processingCircle;
@XmlElement(name = "processingCircle")
public ProcessingCircle getProcessingCircle() {
return processingCircle;
}
public void setProcessingCircle(ProcessingCircle processingCircle) {
this.processingCircle = processingCircle;
}
}
に複雑なXMLをアンマーシャルとなりましたpackage-info.javaファイルはこちら。Javaはオブジェクトをオブジェクト
これは、私は、XSDにXMLを変換し
private List<Object> unMarshalMessages(List<String> messages) {
List<Object> messageObjects = new ArrayList<Object>();
JAXBContext context = null;
try {
context = JAXBContext.newInstance(Class.forName("com.msgs.calpico.TriggerMessage"));
Unmarshaller m = context.createUnmarshaller();
StringReader reader = null;
for (String message : messages) {
reader = new StringReader(message);
messageObjects.add(((com.msgs.calpico.TriggerMessage) m.unmarshal(reader)));
}
} catch (JAXBException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
LOGGER.info("After unmarshal the output messages size: " + messageObjects.size());
return messageObjects;
}
私はアンマーシャリングに使用したコードを追加して元の投稿を編集しました。ご確認ください。 – Rg8
私は(文字列メッセージ:メッセージ)あなたの取得場所からメッセージオブジェクトを見つけることができません。このコードを使用することができます:Unmarshaller unmarshaller; オブジェクトオブジェクト= null; try { unmarshaller = _jaxbContext.createUnmarshaller(); オブジェクト= unmarshaller.unmarshal(新しいStreamSource(新しいStringReader(xml))); } – vijay