jaxbxml前缀问题
我有一个低于1的输入xml文件jaxbxml前缀问题,jaxb,pojo,prefix,Jaxb,Pojo,Prefix,我有一个低于1的输入xml文件 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <cxp:exportedDefect xmlns:cxp="http://export.coverity.com/v7"> <user>admin</user> <project>tev</project> <timeStamp>2014-05-
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cxp:exportedDefect xmlns:cxp="http://export.coverity.com/v7">
<user>admin</user>
<project>tev</project>
<timeStamp>2014-05-23T08:45:08.916+03:00</timeStamp>
<cxp:mergedDefect>
<checkerName>FORWARD_NULL</checkerName>
<checkerSubcategory>deref_constant_null</checkerSubcategory>
<cid>10549</cid>
<componentName>Default.Other</componentName>
<defectStateAttributeValues>
<attributeDefinitionId>
<name>DefectStatus</name>
</attributeDefinitionId>
<attributeValueId>
<name>Dismissed</name>
</attributeValueId>
</defectStateAttributeValues>
<defectStateAttributeValues>
<attributeDefinitionId>
<name>Classification</name>
</attributeDefinitionId>
<attributeValueId>
<name>False Positive</name>
</attributeValueId>
</defectStateAttributeValues>
<defectStateAttributeValues>
<attributeDefinitionId>
<name>Action</name>
</attributeDefinitionId>
<attributeValueId>
<name>Undecided</name>
</attributeValueId>
</defectStateAttributeValues>
<defectStateAttributeValues>
<attributeDefinitionId>
<name>Severity</name>
</attributeDefinitionId>
<attributeValueId>
<name>Unspecified</name>
</attributeValueId>
</defectStateAttributeValues>
<defectStateAttributeValues>
<attributeDefinitionId>
<name>Fix Target</name>
</attributeDefinitionId>
<attributeValueId>
<name>Untargeted</name>
</attributeValueId>
</defectStateAttributeValues>
<defectStateAttributeValues>
<attributeDefinitionId>
<name>Legacy</name>
</attributeDefinitionId>
<attributeValueId>
<name>False</name>
</attributeValueId>
</defectStateAttributeValues>
<defectStateAttributeValues>
<attributeDefinitionId>
<name>Owner</name>
</attributeDefinitionId>
<attributeValueId>
<name>Unassigned</name>
</attributeValueId>
</defectStateAttributeValues>
<defectStateAttributeValues>
<attributeDefinitionId>
<name>TranslatedOwner</name>
</attributeDefinitionId>
<attributeValueId>
<name>Unassigned</name>
</attributeValueId>
</defectStateAttributeValues>
<defectStateAttributeValues>
<attributeDefinitionId>
<name>OwnerName</name>
</attributeDefinitionId>
<attributeValueId>
<name>etevgul</name>
</attributeValueId>
</defectStateAttributeValues>
<defectStateAttributeValues>
<attributeDefinitionId>
<name>Comment</name>
</attributeDefinitionId>
<attributeValueId>
<name></name>
</attributeValueId>
</defectStateAttributeValues>
<defectStateAttributeValues>
<attributeDefinitionId>
<name>ExternalReference</name>
</attributeDefinitionId>
<attributeValueId>
<name></name>
</attributeValueId>
</defectStateAttributeValues>
<domain>STATIC_JAVA</domain>
<filePathname>/user/user-service-impl/src/main/java/com/ericsson/enk/imcp/core/user/service/impl/UserServiceImpl.java</filePathname>
<firstDetected>2014-04-07T13:47:03.730+03:00</firstDetected>
<firstDetectedSnapshotId>10014</firstDetectedSnapshotId>
<functionDisplayName>com.ericsson.enk.imcp.core.user.service.impl.UserServiceImpl.authenticate(com.ericsson.enk.imcp.core.common.domain.Email, java.lang.String)</functionDisplayName>
<lastDetected>2014-05-12T17:06:44.339+03:00</lastDetected>
<lastDetectedSnapshotId>10020</lastDetectedSnapshotId>
<lastFixed>2014-05-09T17:15:27.543+03:00</lastFixed>
<lastTriaged>2014-04-24T16:21:17.912+03:00</lastTriaged>
<mergeKey>e4a7c34660b74135e992f11cdfc5b16d</mergeKey>
<occurrenceCount>1</occurrenceCount>
</cxp:mergedDefect>
<latestSnapshotId>10020</latestSnapshotId>
<streamDefects>
<cxp:streamDefect>
<checkerSubcategoryId>
<checkerName>FORWARD_NULL</checkerName>
<domain>STATIC_JAVA</domain>
<subcategory>deref_constant_null</subcategory>
</checkerSubcategoryId>
<cid>10549</cid>
<defectStateAttributeValues>
<attributeDefinitionId>
<name>DefectStatus</name>
</attributeDefinitionId>
<attributeValueId>
<name>Dismissed</name>
</attributeValueId>
</defectStateAttributeValues>
<defectStateAttributeValues>
<attributeDefinitionId>
<name>Classification</name>
</attributeDefinitionId>
<attributeValueId>
<name>False Positive</name>
</attributeValueId>
</defectStateAttributeValues>
<defectStateAttributeValues>
<attributeDefinitionId>
<name>Action</name>
</attributeDefinitionId>
<attributeValueId>
<name>Undecided</name>
</attributeValueId>
</defectStateAttributeValues>
<defectStateAttributeValues>
<attributeDefinitionId>
<name>Fix Target</name>
</attributeDefinitionId>
<attributeValueId>
<name>Untargeted</name>
</attributeValueId>
</defectStateAttributeValues>
<defectStateAttributeValues>
<attributeDefinitionId>
<name>Severity</name>
</attributeDefinitionId>
<attributeValueId>
<name>Unspecified</name>
</attributeValueId>
</defectStateAttributeValues>
<defectStateAttributeValues>
<attributeDefinitionId>
<name>Legacy</name>
</attributeDefinitionId>
<attributeValueId>
<name>False</name>
</attributeValueId>
</defectStateAttributeValues>
<defectStateAttributeValues>
<attributeDefinitionId>
<name>Comment</name>
</attributeDefinitionId>
<attributeValueId>
<name></name>
</attributeValueId>
</defectStateAttributeValues>
<id>
<defectTriageId>10345</defectTriageId>
<defectTriageVerNum>1</defectTriageVerNum>
<id>21194</id>
<verNum>2</verNum>
</id>
<streamId>
<name>IMCP_V3-java</name>
</streamId>
</cxp:streamDefect>
</streamDefects>
<cxp:checkerProperties>
<subcategoryShortDescription>Explicit null dereferenced</subcategoryShortDescription>
</cxp:checkerProperties>
</cxp:exportedDefect>
其中一个失败元素是xml中的MergedFect,模型为:
package com.ericsson.integration.jira.jaxb.model;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* Created by olgunkaya on 11.09.2014.
*/
public class MergedDefect implements Serializable{
private String checkerName;
private String checkerSubcategory;
private String cid;
private String componentName;
private List<DefectStateAttributeValues> defectStateAttributeValues;
private String domain;
private String filePathname;
private Date firstDetected;
private String firstDetectedSnapshotId;
private String functionDisplayName;
private Date lastDetected;
private String lastDetectedSnapshotId;
private Date lastFixed;
private Date lastTriaged;
private String mergeKey;
private String occurrenceCount;
public String getCheckerName() {
return checkerName;
}
@XmlElement
public void setCheckerName(String checkerName) {
this.checkerName = checkerName;
}
public String getCheckerSubcategory() {
return checkerSubcategory;
}
@XmlElement
public void setCheckerSubcategory(String checkerSubcategory) {
this.checkerSubcategory = checkerSubcategory;
}
public String getCid() {
return cid;
}
@XmlElement
public void setCid(String cid) {
this.cid = cid;
}
public String getComponentName() {
return componentName;
}
@XmlElement
public void setComponentName(String componentName) {
this.componentName = componentName;
}
public List<DefectStateAttributeValues> getDefectStateAttributeValues() {
return defectStateAttributeValues;
}
@XmlElement
public void setDefectStateAttributeValues(List<DefectStateAttributeValues> defectStateAttributeValues) {
this.defectStateAttributeValues = defectStateAttributeValues;
}
public String getDomain() {
return domain;
}
@XmlElement
public void setDomain(String domain) {
this.domain = domain;
}
public String getFilePathname() {
return filePathname;
}
@XmlElement
public void setFilePathname(String filePathname) {
this.filePathname = filePathname;
}
public Date getFirstDetected() {
return firstDetected;
}
@XmlElement
public void setFirstDetected(Date firstDetected) {
this.firstDetected = firstDetected;
}
public String getFirstDetectedSnapshotId() {
return firstDetectedSnapshotId;
}
@XmlElement
public void setFirstDetectedSnapshotId(String firstDetectedSnapshotId) {
this.firstDetectedSnapshotId = firstDetectedSnapshotId;
}
public String getFunctionDisplayName() {
return functionDisplayName;
}
@XmlElement
public void setFunctionDisplayName(String functionDisplayName) {
this.functionDisplayName = functionDisplayName;
}
public Date getLastDetected() {
return lastDetected;
}
@XmlElement
public void setLastDetected(Date lastDetected) {
this.lastDetected = lastDetected;
}
public String getLastDetectedSnapshotId() {
return lastDetectedSnapshotId;
}
@XmlElement
public void setLastDetectedSnapshotId(String lastDetectedSnapshotId) {
this.lastDetectedSnapshotId = lastDetectedSnapshotId;
}
public Date getLastFixed() {
return lastFixed;
}
@XmlElement
public void setLastFixed(Date lastFixed) {
this.lastFixed = lastFixed;
}
public Date getLastTriaged() {
return lastTriaged;
}
@XmlElement
public void setLastTriaged(Date lastTriaged) {
this.lastTriaged = lastTriaged;
}
public String getMergeKey() {
return mergeKey;
}
@XmlElement
public void setMergeKey(String mergeKey) {
this.mergeKey = mergeKey;
}
public String getOccurrenceCount() {
return occurrenceCount;
}
@XmlElement
public void setOccurrenceCount(String occurrenceCount) {
this.occurrenceCount = occurrenceCount;
}
}
多亏了这篇帖子上的一个老答案。 我用同样的方法删除了所有前缀。现在它开始工作了。 只是为了解决这些问题。可以扩展
XMLFilterImpl
并覆盖startElement和endElement方法。然后可以修改传递给此方法的qName
参数。根据您的需要,实现可能会有所不同
您还应该注意用于将xml映射到的POJO。您可能有一些Sax异常
在这种情况下,您可能需要稍微使用xmlfilter实现
package com.ericsson.integration.jira.jaxb.model;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* Created by olgunkaya on 11.09.2014.
*/
public class MergedDefect implements Serializable{
private String checkerName;
private String checkerSubcategory;
private String cid;
private String componentName;
private List<DefectStateAttributeValues> defectStateAttributeValues;
private String domain;
private String filePathname;
private Date firstDetected;
private String firstDetectedSnapshotId;
private String functionDisplayName;
private Date lastDetected;
private String lastDetectedSnapshotId;
private Date lastFixed;
private Date lastTriaged;
private String mergeKey;
private String occurrenceCount;
public String getCheckerName() {
return checkerName;
}
@XmlElement
public void setCheckerName(String checkerName) {
this.checkerName = checkerName;
}
public String getCheckerSubcategory() {
return checkerSubcategory;
}
@XmlElement
public void setCheckerSubcategory(String checkerSubcategory) {
this.checkerSubcategory = checkerSubcategory;
}
public String getCid() {
return cid;
}
@XmlElement
public void setCid(String cid) {
this.cid = cid;
}
public String getComponentName() {
return componentName;
}
@XmlElement
public void setComponentName(String componentName) {
this.componentName = componentName;
}
public List<DefectStateAttributeValues> getDefectStateAttributeValues() {
return defectStateAttributeValues;
}
@XmlElement
public void setDefectStateAttributeValues(List<DefectStateAttributeValues> defectStateAttributeValues) {
this.defectStateAttributeValues = defectStateAttributeValues;
}
public String getDomain() {
return domain;
}
@XmlElement
public void setDomain(String domain) {
this.domain = domain;
}
public String getFilePathname() {
return filePathname;
}
@XmlElement
public void setFilePathname(String filePathname) {
this.filePathname = filePathname;
}
public Date getFirstDetected() {
return firstDetected;
}
@XmlElement
public void setFirstDetected(Date firstDetected) {
this.firstDetected = firstDetected;
}
public String getFirstDetectedSnapshotId() {
return firstDetectedSnapshotId;
}
@XmlElement
public void setFirstDetectedSnapshotId(String firstDetectedSnapshotId) {
this.firstDetectedSnapshotId = firstDetectedSnapshotId;
}
public String getFunctionDisplayName() {
return functionDisplayName;
}
@XmlElement
public void setFunctionDisplayName(String functionDisplayName) {
this.functionDisplayName = functionDisplayName;
}
public Date getLastDetected() {
return lastDetected;
}
@XmlElement
public void setLastDetected(Date lastDetected) {
this.lastDetected = lastDetected;
}
public String getLastDetectedSnapshotId() {
return lastDetectedSnapshotId;
}
@XmlElement
public void setLastDetectedSnapshotId(String lastDetectedSnapshotId) {
this.lastDetectedSnapshotId = lastDetectedSnapshotId;
}
public Date getLastFixed() {
return lastFixed;
}
@XmlElement
public void setLastFixed(Date lastFixed) {
this.lastFixed = lastFixed;
}
public Date getLastTriaged() {
return lastTriaged;
}
@XmlElement
public void setLastTriaged(Date lastTriaged) {
this.lastTriaged = lastTriaged;
}
public String getMergeKey() {
return mergeKey;
}
@XmlElement
public void setMergeKey(String mergeKey) {
this.mergeKey = mergeKey;
}
public String getOccurrenceCount() {
return occurrenceCount;
}
@XmlElement
public void setOccurrenceCount(String occurrenceCount) {
this.occurrenceCount = occurrenceCount;
}
}
File file = new File("/Users/olgunkaya/Downloads/atlassian-jira-rest-java-client-890e21ab0a7b/" +
"jira-integration/resources/cov-export5653165670998483522.xml");
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
CoverityDefect coverityDefectt = (CoverityDefect) jaxbUnmarshaller.unmarshal(file);
System.out.println(coverityDefectt);