[英]JAXB With Axis2 Putting Object ID while Serializing
我在以下技術堆棧中遇到了一個非常奇怪的問題:
具有集成JAXB的Weblogic 12c JDK 1.7 Axis2 1.5.2
活動:將項目從Weblogic 10.3.6升級到12.1.1,包括將JDK從1.6升級到1.7
問題描述:在創建OM元素時,JAXB會將子對象的對象ID而不是參數值放在子對象下。 在JDK 1.7中只能看到該問題,因為它在JDK 1.6中可以正常運行
Request.java
import java.math.BigInteger;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element ref="{http://w3.org.com/spec/prd/services/2011/02}NumberOfNotes"/>
* <element ref="{http://w3.org.com/spec/prd/services/2011/02}NoteData"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"NumberOfNotes",
"NoteData"
})
@XmlRootElement(name = "Request")
public class Request {
@XmlElement(required = true)
@XmlSchemaType(name = "nonNegativeInteger")
protected BigInteger NumberOfNotes;
@XmlElement(name = "NoteData", required = true)
protected NoteData NoteData;
/**
* Gets the value of the NumberOfNotes property.
*
* @return
* possible object is
* {@link BigInteger }
*
*/
public BigInteger getNumberOfNotes() {
return NumberOfNotes;
}
/**
* Sets the value of the NumberOfNotes property.
*
* @param value
* allowed object is
* {@link BigInteger }
*
*/
public void setNumberOfNotes(BigInteger value) {
this.NumberOfNotes = value;
}
/**
* Gets the value of the NoteData property.
*
* @return
* possible object is
* {@link NoteData }
*
*/
public NoteData getNoteData() {
return NoteData;
}
/**
* Sets the value of the NoteData property.
*
* @param value
* allowed object is
* {@link NoteData }
*
*/
public void setNoteData(NoteData value) {
this.NoteData = value;
}
}
NoteData.java
package com.org.w3.spec.prd.services._2011._02;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="NoteDataDetails" maxOccurs="50" minOccurs="0">
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element ref="{http://w3.org.com/spec/prd/services/2011/02}numberOfNoteLines"/>
* <sequence>
* <element ref="{http://w3.org.com/spec/prd/services/2011/02}NoteLineText" maxOccurs="10" minOccurs="0"/>
* </sequence>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </element>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"NoteDataDetails"
})
@XmlRootElement(name = "NoteData")
public class NoteData {
protected List<NoteData.NoteDataDetails> NoteDataDetails;
/**
* Gets the value of the NoteDataDetails property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the NoteDataDetails property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getNoteDataDetails().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link NoteData.NoteDataDetails }
*
*
*/
public List<NoteData.NoteDataDetails> getNoteDataDetails() {
if (NoteDataDetails == null) {
NoteDataDetails = new ArrayList<NoteData.NoteDataDetails>();
}
return this.NoteDataDetails;
}
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element ref="{http://w3.org.com/spec/prd/services/2011/02}numberOfNoteLines"/>
* <sequence>
* <element ref="{http://w3.org.com/spec/prd/services/2011/02}NoteLineText" maxOccurs="10" minOccurs="0"/>
* </sequence>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"numberOfNoteLines",
"NoteLineText"
})
public static class NoteDataDetails {
@XmlElement(required = true)
protected BigInteger numberOfNoteLines;
@XmlElement(required = true)
protected List<NoteLineText> NoteLineText;
/**
* Gets the value of the numberOfNoteLines property.
*
* @return
* possible object is
* {@link BigInteger }
*
*/
public BigInteger getNumberOfNoteLines() {
return numberOfNoteLines;
}
/**
* Sets the value of the numberOfNoteLines property.
*
* @param value
* allowed object is
* {@link BigInteger }
*
*/
public void setNumberOfNoteLines(BigInteger value) {
this.numberOfNoteLines = value;
}
/**
* Gets the value of the NoteLineText property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the NoteLineText property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getNoteLineText().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link NoteLineText }
*
*
*/
public List<NoteLineText> getNoteLineText() {
if (NoteLineText == null) {
NoteLineText = new ArrayList<NoteLineText>();
}
return this.NoteLineText;
}
}
}
NoteLoneText.java
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for anonymous complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="Line">
* <simpleType>
* <restriction base="{http://www.w3.org/2001/XMLSchema}string">
* <maxLength value="50"/>
* <whiteSpace value="collapse"/>
* </restriction>
* </simpleType>
* </element>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"line"
})
@XmlRootElement(name = "NoteLineText")
public class NoteLineText {
@XmlElement(name = "Line", required = true)
protected String line;
/**
* Gets the value of the line property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getLine() {
return line;
}
/**
* Sets the value of the line property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setLine(String value) {
this.line = value;
}
}
SendNoteStub.java
private org.apache.axiom.om.OMElement toOM(com.org.w3.spec.prd.services._2011._02.prdAddNoteRes param, boolean optimizeContent)
throws org.apache.axis2.AxisFault {
try {
javax.xml.bind.JAXBContext context = wsContext;
javax.xml.bind.Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
org.apache.axiom.om.OMFactory factory = org.apache.axiom.om.OMAbstractFactory.getOMFactory();
JaxbRIDataSource source = new JaxbRIDataSource( com.org.w3.spec.prd.services._2011._02.prdAddNoteRes.class,
param,
marshaller,
"http://w3.org.com/spec/prd/services/2011/02",
"AddNoteRes");
org.apache.axiom.om.OMNamespace namespace = factory.createOMNamespace("http://w3.org.com/spec/prd/services/2011/02",
null);
return factory.createOMElement(source, "prdAddNoteRes", namespace);
} catch (javax.xml.bind.JAXBException bex){
throw org.apache.axis2.AxisFault.makeFault(bex);
}
}
生成的XML:
<PrdAddLoanNoteReq xmlns="http://w3.org.com/spec/Prd/services/2011/02"><transactionId>BZNSQT</transactionId><numberOfLoanNotes>1</numberOfLoanNotes><LoanNoteData><loanNoteDataDetails><numberOfLoanNoteLines>3</numberOfLoanNoteLines><loanNoteLineText>com.org.w3.spec.Prd.services._2011._02.LoanNoteLineText@1182716</loanNoteLineText><loanNoteLineText>com.org.w3.spec.Prd.services._2011._02.LoanNoteLineText@58ae15e9</loanNoteLineText><loanNoteLineText>com.org.w3.spec.Prd.services._2011._02.LoanNoteLineText@d20a17b</loanNoteLineText></loanNoteDataDetails></LoanNoteData></PrdAddLoanNoteReq>
生成的XML中的問題是,在LoanNoteLineText標記下,JAXB放置了對象ID而不是參數Line的值。
在這方面的任何幫助都將受到高度贊賞。
非常感謝。
由於加載了不正確的JAXB實現而發生了此問題。 更新Weblogic啟動參數解決了該問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.