gpt4 book ai didi

java - JAXB 与 Axis2 在序列化时放置对象 ID

转载 作者:行者123 更新时间:2023-12-01 12:08:46 25 4
gpt4 key购买 nike

我遇到了以下技术堆栈的非常奇怪的问题:

Weblogic 12cJDK 1.7带有集成 JAXB 的 Axis2 1.5.2

Activity :将项目从 Weblogic 10.3.6 升级到 12.1.1,包括 JDK 从 1.6 升级到 1.7

问题描述:创建 OM 元素时,JAXB 将子对象的对象 ID 而不是参数值放在子对象下。该问题仅在 JDK 1.7 中出现,而在 JDK 1.6 中运行完美

请求.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>
* &lt;complexType>
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element ref="{http://w3.org.com/spec/prd/services/2011/02}NumberOfNotes"/>
* &lt;element ref="{http://w3.org.com/spec/prd/services/2011/02}NoteData"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/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>
* &lt;complexType>
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="NoteDataDetails" maxOccurs="50" minOccurs="0">
* &lt;complexType>
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element ref="{http://w3.org.com/spec/prd/services/2011/02}numberOfNoteLines"/>
* &lt;sequence>
* &lt;element ref="{http://w3.org.com/spec/prd/services/2011/02}NoteLineText" maxOccurs="10" minOccurs="0"/>
* &lt;/sequence>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* &lt;/element>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/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>
* &lt;complexType>
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element ref="{http://w3.org.com/spec/prd/services/2011/02}numberOfNoteLines"/>
* &lt;sequence>
* &lt;element ref="{http://w3.org.com/spec/prd/services/2011/02}NoteLineText" maxOccurs="10" minOccurs="0"/>
* &lt;/sequence>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/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>
* &lt;complexType>
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="Line">
* &lt;simpleType>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}string">
* &lt;maxLength value="50"/>
* &lt;whiteSpace value="collapse"/>
* &lt;/restriction>
* &lt;/simpleType>
* &lt;/element>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/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 启动参数解决了该问题。

关于java - JAXB 与 Axis2 在序列化时放置对象 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27392633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com