我正在尝试将XML解组为POJO VmML类以将其传递给我们的系统。 POJO类是使用jaxb2 maven插件从dtd文件创建的。当我在karaf中使用feature camel-jaxb时,我能够将XML文件解组为VmML类的对象而没有任何问题,但由于某些原因我不得不撤回这种方法,最后我最终得到了camel-jacksonxml。
现在路线中我正在使用unmarshall标签,如下所示。
<dataFormats>
<jacksonxml id="jack" unmarshalTypeName="com.company.generated.VmML"/>
</dataFormats>
<rest path="/service"
consumes="application/xml"
produces="text/plain">
<post uri="/requestXmlCfg"
type="com.company.generated.VmML"
outType="java.lang.String">
<route>
<unmarshal ref="jack"/>
<to uri="bean:messageProcessot?method=process"/>
</route>
</post>
</rest>
我想强调的是,当我使用简单的camel-jaxb功能时,它可以在没有解组标签的情况下提前工作。
现在我得到了经常出现的异常,但在我的情况下,解决方案不正确,因为提供了数据,我不想跳过任何内容。错误是:
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "ReportType" (class com.company.generated.CarrierReport), not marked as ignorable (3 known properties: "CarrierReportSnapshot", "CarrierReportHeader", "CarrierReportPeriod"])
at [Source: org.apache.camel.component.netty4.http.NettyChannelBufferStreamCache@612e834b; line: 6, column: 42] (through reference chain: com.company.generated.VmML["CarrierReport"]->java.util.ArrayList[0]->com.company.generated.CarrierReport["ReportType"])
POJO课程是在http://www.vmml.org/spec/VmML_v0.1.dtd
的基础上创建的XML正确填写
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE VmML SYSTEM "http://www.vmml.org/spec/VmML_v0.1.dtd">
<VmML Version="0.1">
<CarrierReport>
<CarrierReportHeader>
<ReportType SystemReference="aa">VMML</ReportType>
<ReportTimestamp Timezone="0" TimeFormat="RFC822">Tue, 07 May 2013 15:21:14 %2B0000</ReportTimestamp>
<SenderId SystemReference="aa">aa</SenderId>
<ReceiverId SystemReference="aa">aa</ReceiverId>
<SystemSource>aa</SystemSource>
<SystemDestination>aa</SystemDestination>
</CarrierReportHeader>
<CarrierReportSnapshot>
<Event>
<EventHeader>
<EventTimestamp Timezone="0" TimeFormat="RFC822">Tue, 07 May 2013 15:21:14 %2B0000</EventTimestamp>
<EventCode SystemReference="aa">aa</EventCode>
<EventText>aa</EventText>
</EventHeader>
</Event>
</CarrierReportSnapshot>
</CarrierReport>
</VmML>
VMML类:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"carrierReport"
})
@XmlRootElement(name = "VmML")
public class VmML {
@XmlAttribute(name = "Version", required = true)
@XmlJavaTypeAdapter(NormalizedStringAdapter.class)
protected String version;
@XmlAttribute(name = "id")
@XmlJavaTypeAdapter(NormalizedStringAdapter.class)
protected String id;
@XmlElement(name = "CarrierReport", required = true)
protected List<CarrierReport> carrierReport;
public String getVersion() {
return version;
}
public void setVersion(String value) {
this.version = value;
}
public String getId() {
return id;
}
public void setId(String value) {
this.id = value;
}
public List<CarrierReport> getCarrierReport() {
if (carrierReport == null) {
carrierReport = new ArrayList<CarrierReport>();
}
return this.carrierReport;
}
}
CarrierReport类:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"carrierReportHeader",
"carrierReportSnapshot",
"carrierReportPeriod"
})
@XmlRootElement(name = "CarrierReport")
public class CarrierReport {
@XmlElement(name = "CarrierReportHeader", required = true)
protected CarrierReportHeader carrierReportHeader;
@XmlElement(name = "CarrierReportSnapshot")
protected CarrierReportSnapshot carrierReportSnapshot;
@XmlElement(name = "CarrierReportPeriod")
protected CarrierReportPeriod carrierReportPeriod;
public CarrierReportHeader getCarrierReportHeader() {
return carrierReportHeader;
}
public void setCarrierReportHeader(CarrierReportHeader value) {
this.carrierReportHeader = value;
}
public CarrierReportSnapshot getCarrierReportSnapshot() {
return carrierReportSnapshot;
}
public void setCarrierReportSnapshot(CarrierReportSnapshot value) {
this.carrierReportSnapshot = value;
}
public CarrierReportPeriod getCarrierReportPeriod() {
return carrierReportPeriod;
}
public void setCarrierReportPeriod(CarrierReportPeriod value) {
this.carrierReportPeriod = value;
}
}
REPORTTYPE
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"value"
})
@XmlRootElement(name = "ReportType")
public class ReportType {
@XmlAttribute(name = "SystemReference")
@XmlJavaTypeAdapter(NormalizedStringAdapter.class)
protected String systemReference;
@XmlValue
protected String value;
public String getSystemReference() {
return systemReference;
}
public void setSystemReference(String value) {
this.systemReference = value;
}
public String getvalue() {
return value;
}
public void setvalue(String value) {
this.value = value;
}
}
Vmml&gt; Carier报告&gt; Carier报告标题&gt; ReportType类
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"reportType",
"reportTimestamp",
"senderId",
"receiverId",
"systemSource",
"systemDestination",
"missionId",
"missionName"
})
@XmlRootElement(name = "CarrierReportHeader")
public class CarrierReportHeader {
@XmlElement(name = "ReportType", required = true)
protected ReportType reportType;
@XmlElement(name = "ReportTimestamp", required = true)
protected ReportTimestamp reportTimestamp;
@XmlElement(name = "SenderId", required = true)
protected SenderId senderId;
@XmlElement(name = "ReceiverId")
protected ReceiverId receiverId;
@XmlElement(name = "SystemSource", required = true)
protected String systemSource;
@XmlElement(name = "SystemDestination")
protected String systemDestination;
@XmlElement(name = "MissionId")
protected MissionId missionId;
@XmlElement(name = "MissionName")
protected String missionName;
public ReportType getReportType() {
return reportType;
}
public void setReportType(ReportType value) {
this.reportType = value;
}
public ReportTimestamp getReportTimestamp() {
return reportTimestamp;
}
public void setReportTimestamp(ReportTimestamp value) {
this.reportTimestamp = value;
}
public SenderId getSenderId() {
return senderId;
}
public void setSenderId(SenderId value) {
this.senderId = value;
}
public ReceiverId getReceiverId() {
return receiverId;
}
public void setReceiverId(ReceiverId value) {
this.receiverId = value;
}
public String getSystemSource() {
return systemSource;
}
public void setSystemSource(String value) {
this.systemSource = value;
}
public String getSystemDestination() {
return systemDestination;
}
public void setSystemDestination(String value) {
this.systemDestination = value;
}
public MissionId getMissionId() {
return missionId;
}
public void setMissionId(MissionId value) {
this.missionId = value;
}
public String getMissionName() {
return missionName;
}
public void setMissionName(String value) {
this.missionName = value;
}
}