1

我正在尝试使用自定义转换器为此 SupplierOrderCharge 对象创建一种聚合,在该对象中我总结了列表中的所有值。

如果我删除转换器注释,下面列出的异常就会消失。这是一个有效的配置吗?我可以为这样的吸气剂方法放置一个变压器吗?或者它可能是 MOXy 中的一个错误?

这是我的代码:

@XmlElement
@XmlTransformation
@XmlReadTransformer(transformerClass = GeneralAttributeMarkerTransformer.class)
@XmlWriteTransformers({ @XmlWriteTransformer(xmlPath = "ORDER_HEADER/SHIPPING_INFO/SHIPMENT_CODE/text()", transformerClass = ShippingInfoTransformer.class),
@XmlWriteTransformer(xmlPath = "ORDER_HEADER/SHIPPING_INFO/SHIPPING_COST_EX_VAT/text()", transformerClass = ShippingInfoTransformer.class),
@XmlWriteTransformer(xmlPath = "ORDER_HEADER/SHIPPING_INFO/SHIPPING_COST_VAT/text()", transformerClass = ShippingInfoTransformer.class),
@XmlWriteTransformer(xmlPath = "ORDER_HEADER/SHIPPING_INFO/SHIPPING_COST_INC_VAT/text()", transformerClass = ShippingInfoTransformer.class), })
@Transient
protected SupplierOrderCharge getShippingInfo() {
    for (final SupplierOrderCharge soCharge : getOrderCharges()) {
        if (EntryType.SHIPPING.equals(soCharge.getEntryType())) {
            return soCharge;
        }
    }
    return null;
}

我得到这个例外:

javax.xml.bind.JAXBException: 
Descriptor Exceptions: 
---------------------------------------------------------

Exception [EclipseLink-60] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The method [] or [getShippingInfo] is not defined in the object [com.debijenkorf.data.model.supplier.SupplierOrder].
Internal Exception: java.lang.NoSuchMethodException: com.debijenkorf.data.model.supplier.SupplierOrder.(com.debijenkorf.data.model.supplier.SupplierOrderCharge)
Mapping: org.eclipse.persistence.oxm.mappings.XMLTransformationMapping[shippingInfo]
Descriptor: XMLDescriptor(com.debijenkorf.data.model.supplier.SupplierOrder --> [DatabaseTable(SALES_ORDER)])

Runtime Exceptions: 
---------------------------------------------------------

java.lang.NullPointerException

- with linked exception:
[Exception [EclipseLink-0] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions: 
---------------------------------------------------------

Exception [EclipseLink-60] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The method [] or [getShippingInfo] is not defined in the object [com.debijenkorf.data.model.supplier.SupplierOrder].
Internal Exception: java.lang.NoSuchMethodException: com.debijenkorf.data.model.supplier.SupplierOrder.(com.debijenkorf.data.model.supplier.SupplierOrderCharge)
Mapping: org.eclipse.persistence.oxm.mappings.XMLTransformationMapping[shippingInfo]
Descriptor: XMLDescriptor(com.debijenkorf.data.model.supplier.SupplierOrder --> [DatabaseTable(SALES_ORDER)])

Runtime Exceptions: 
---------------------------------------------------------

java.lang.NullPointerException
]
at org.eclipse.persistence.jaxb.JAXBContext$ContextPathInput.createContextState(JAXBContext.java:771)
at org.eclipse.persistence.jaxb.JAXBContext$ContextPathInput.createContextState(JAXBContext.java:711)
at org.eclipse.persistence.jaxb.JAXBContext.<init>(JAXBContext.java:157)
at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:134)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:128)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:249)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:244)
at com.debijenkorf.services.core.JaxbMoxyMarUn.marshal(JaxbMoxyMarUn.java:48)
at com.debijenkorf.services.fc4.JaxbMarUnFC1Test.testMarshal(JaxbMarUnFC1Test.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions: 
---------------------------------------------------------

Exception [EclipseLink-60] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The method [] or [getShippingInfo] is not defined in the object [com.debijenkorf.data.model.supplier.SupplierOrder].
Internal Exception: java.lang.NoSuchMethodException: com.debijenkorf.data.model.supplier.SupplierOrder.(com.debijenkorf.data.model.supplier.SupplierOrderCharge)
Mapping: org.eclipse.persistence.oxm.mappings.XMLTransformationMapping[shippingInfo]
Descriptor: XMLDescriptor(com.debijenkorf.data.model.supplier.SupplierOrder --> [DatabaseTable(SALES_ORDER)])

Runtime Exceptions: 
---------------------------------------------------------

java.lang.NullPointerException

at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:638)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:574)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:533)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:777)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:735)
at org.eclipse.persistence.oxm.XMLContext$XMLContextState.<init>(XMLContext.java:857)
at org.eclipse.persistence.oxm.XMLContext$XMLContextState.<init>(XMLContext.java:832)
at org.eclipse.persistence.oxm.XMLContext.<init>(XMLContext.java:193)
at org.eclipse.persistence.jaxb.JAXBContext$ContextPathInput.createContextState(JAXBContext.java:797)
at org.eclipse.persistence.jaxb.JAXBContext$ContextPathInput.createContextState(JAXBContext.java:769)
... 37 more
4

1 回答 1

1

这里可能有一个错误。您介意在下面的链接中输入一个,并且可以提供一个示例来演示您所看到的问题吗?

我在下面添加了一些示例代码,可以XmlTransformationMapping为我正确创建一个。我做了以下事情:

  • 删除了@XmlElement注释。
  • 公开了getShippingInfo()方法。
  • 添加了一个setShippingInfo(SupplierOrderCharge s)方法。
package forum13075432;

import java.util.List;
import org.eclipse.persistence.oxm.annotations.*;

public class Root {

    @XmlTransformation
    @XmlReadTransformer(transformerClass = GeneralAttributeMarkerTransformer.class)
    @XmlWriteTransformers({
            @XmlWriteTransformer(xmlPath = "ORDER_HEADER/SHIPPING_INFO/SHIPMENT_CODE/text()", transformerClass = ShippingInfoTransformer.class),
            @XmlWriteTransformer(xmlPath = "ORDER_HEADER/SHIPPING_INFO/SHIPPING_COST_EX_VAT/text()", transformerClass = ShippingInfoTransformer.class),
            @XmlWriteTransformer(xmlPath = "ORDER_HEADER/SHIPPING_INFO/SHIPPING_COST_VAT/text()", transformerClass = ShippingInfoTransformer.class),
            @XmlWriteTransformer(xmlPath = "ORDER_HEADER/SHIPPING_INFO/SHIPPING_COST_INC_VAT/text()", transformerClass = ShippingInfoTransformer.class), })
    public SupplierOrderCharge getShippingInfo() {
        for (final SupplierOrderCharge soCharge : getOrderCharges()) {
            if (EntryType.SHIPPING.equals(soCharge.getEntryType())) {
                return soCharge;
            }
        }
        return null;
    }

    public void setShippingInfo(SupplierOrderCharge s) {
    }

    private List<SupplierOrderCharge> getOrderCharges() {
        // TODO Auto-generated method stub
        return null;
    }

}
于 2012-10-25T20:36:34.777 回答