2

我正在努力从 JAXB-RI 迁移到 moxy。

我已经迁移了大部分注释(我在 RI 和 Moxy 之间的行为上遇到了一些显着差异),现在我正在与一个奇怪的异常作斗争。我已将其缩小到在现有应用程序中运行的这个简单案例。

@XmlRootElement(name="StringMap")
public class StringMap extends StringMapBase  
{
}

@XmlTransient
class StringMapBase extends HashMap<String,String>
{

}

StringMap 是我试图序列化的类,这无法在 glassfish 中部署,只要我更改 StringMapBase 使其不扩展 HashMap 部署就可以了。如果 StringMapBase 扩展 ArrayList 我会得到同样的错误。

moxy 版本是:- 实施版本:2.3.2.v20111125-r10461

glassfish 版本是:- 3.1.2.2-5 这是使用 3.1-43 中的 glassfish 升级工具升级的,而不是全新安装(全新安装是不可能的,因为我必须复制我们的客户将经历的过程)

在将其作为针对 moxy 的错误之前,我还有什么明显的可以尝试的吗?在过去的几天里,我一直在用头撞墙才能走到这一步,但如果我不能让它工作,我必须解开我的所有更改并返回 JAXB-RI!

提前谢谢了。欧文

===== 异常

[#|2013-04-08T11:58:30.805+0100|SEVERE|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=24;_ThreadName=Thread-2;|javax.xml.bind.JAXBException
 - with linked exception:
[java.lang.reflect.MalformedParameterizedTypeException]
    at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:832)
    at org.eclipse.persistence.jaxb.JAXBContext.<init>(JAXBContext.java:143)
    at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:142)
    at com.sun.xml.ws.db.toplink.JAXBContextFactory.newContext(JAXBContextFactory.java:180)
    at com.sun.xml.ws.spi.db.BindingContextFactory.create(BindingContextFactory.java:191)
    at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:213)
    at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:186)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:186)
    at com.sun.xml.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:111)
    at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:318)
    at com.sun.xml.ws.db.DatabindingImpl.<init>(DatabindingImpl.java:99)
    at com.sun.xml.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:74)
    at com.sun.xml.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:58)
    at com.sun.xml.ws.db.DatabindingFactoryImpl.createRuntime(DatabindingFactoryImpl.java:130)
    at com.sun.xml.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:433)
    at com.sun.xml.ws.server.EndpointFactory.create(EndpointFactory.java:268)
    at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:145)
    at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:569)
    at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:552)
    at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:623)
    at org.glassfish.webservices.WSServletContextListener.registerEndpoint(WSServletContextListener.java:282)
    at org.glassfish.webservices.WSServletContextListener.contextInitialized(WSServletContextListener.java:102)
    at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:4750)
    at com.sun.enterprise.web.WebModule.contextListenerStart(WebModule.java:550)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5366)
    at com.sun.enterprise.web.WebModule.start(WebModule.java:498)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:917)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:733)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2019)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1669)
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:109)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
    at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
    at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
    at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
    at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
    at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.reflect.MalformedParameterizedTypeException
    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:42)
    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(ParameterizedTypeImpl.java:35)
    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:77)
    at sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(CoreReflectionFactory.java:86)
    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:122)
    at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:31)
    at sun.reflect.generics.repository.FieldRepository.getGenericType(FieldRepository.java:67)
    at java.lang.reflect.Field.getGenericType(Field.java:223)
    at org.eclipse.persistence.jaxb.javamodel.reflection.JavaFieldImpl.getResolvedType(JavaFieldImpl.java:96)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.getFieldPropertiesForClass(AnnotationsProcessor.java:1654)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.getFieldPropertiesForClass(AnnotationsProcessor.java:1637)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.getPublicMemberPropertiesForClass(AnnotationsProcessor.java:2662)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.getPropertiesForClass(AnnotationsProcessor.java:1629)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.buildTypeInfo(AnnotationsProcessor.java:683)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.postBuildTypeInfo(AnnotationsProcessor.java:597)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.processClassesAndProperties(AnnotationsProcessor.java:234)
    at org.eclipse.persistence.jaxb.compiler.Generator.<init>(Generator.java:147)
    at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:829)
    ... 64 more
|#]

[#|2013-04-08T11:58:30.805+0100|WARNING|glassfish3.1.2|javax.enterprise.webservices.org.glassfish.webservices|_ThreadID=24;_ThreadName=Thread-2;|Deployment failed
com.sun.xml.ws.spi.db.DatabindingException
    at com.sun.xml.ws.db.toplink.JAXBContextFactory.newContext(JAXBContextFactory.java:185)
    at com.sun.xml.ws.spi.db.BindingContextFactory.create(BindingContextFactory.java:191)
    at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:213)
    at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:186)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:186)
    at com.sun.xml.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:111)
    at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:318)
    at com.sun.xml.ws.db.DatabindingImpl.<init>(DatabindingImpl.java:99)
    at com.sun.xml.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:74)
    at com.sun.xml.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:58)
    at com.sun.xml.ws.db.DatabindingFactoryImpl.createRuntime(DatabindingFactoryImpl.java:130)
    at com.sun.xml.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:433)
    at com.sun.xml.ws.server.EndpointFactory.create(EndpointFactory.java:268)
    at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:145)
    at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:569)
    at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:552)
    at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:623)
    at org.glassfish.webservices.WSServletContextListener.registerEndpoint(WSServletContextListener.java:282)
    at org.glassfish.webservices.WSServletContextListener.contextInitialized(WSServletContextListener.java:102)
    at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:4750)
    at com.sun.enterprise.web.WebModule.contextListenerStart(WebModule.java:550)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5366)
    at com.sun.enterprise.web.WebModule.start(WebModule.java:498)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:917)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:733)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2019)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1669)
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:109)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:130)
    at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:269)
    at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:301)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)
    at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
    at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
    at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
    at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
    at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:662)
Caused by: javax.xml.bind.JAXBException
 - with linked exception:
[java.lang.reflect.MalformedParameterizedTypeException]
    at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:832)
    at org.eclipse.persistence.jaxb.JAXBContext.<init>(JAXBContext.java:143)
    at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:142)
    at com.sun.xml.ws.db.toplink.JAXBContextFactory.newContext(JAXBContextFactory.java:180)
    ... 61 more
Caused by: java.lang.reflect.MalformedParameterizedTypeException
    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:42)
    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(ParameterizedTypeImpl.java:35)
    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:77)
    at sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(CoreReflectionFactory.java:86)
    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:122)
    at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:31)
    at sun.reflect.generics.repository.FieldRepository.getGenericType(FieldRepository.java:67)
    at java.lang.reflect.Field.getGenericType(Field.java:223)
    at org.eclipse.persistence.jaxb.javamodel.reflection.JavaFieldImpl.getResolvedType(JavaFieldImpl.java:96)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.getFieldPropertiesForClass(AnnotationsProcessor.java:1654)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.getFieldPropertiesForClass(AnnotationsProcessor.java:1637)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.getPublicMemberPropertiesForClass(AnnotationsProcessor.java:2662)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.getPropertiesForClass(AnnotationsProcessor.java:1629)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.buildTypeInfo(AnnotationsProcessor.java:683)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.postBuildTypeInfo(AnnotationsProcessor.java:597)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.processClassesAndProperties(AnnotationsProcessor.java:234)
    at org.eclipse.persistence.jaxb.compiler.Generator.<init>(Generator.java:147)
    at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:829)
    ... 64 more
|#]

[#|2013-04-08T11:58:31.148+0100|SEVERE|glassfish3.1.2|org.apache.catalina.core.StandardContext|_ThreadID=24;_ThreadName=Thread-2;|PWC1306: Startup of context /WebServices failed due to previous errors|#]
4

1 回答 1

0

我已经重现了您所看到的问题。您可以使用以下错误来跟踪我们在此问题上的进展:


解决方法

由于您@XmlTransient在超类上使用(请参阅: http ://blog.bdoughan.com/2011/06/ignoring-inheritance-with-xmltransient.html ),如果没有您尝试继承的映射属性,那么您可以使用 MOXy 的外部映射文件来覆盖类的超类型StringMap

oxm.xml

下面是一个重写超类StringMap.

<?xml version="1.0"?>
<xml-bindings
    xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
    package-name="bug405170">
    <java-types>
        <java-type name="StringMap" super-type="java.lang.Object"/>
     </java-types>
</xml-bindings>

演示

package bug405170;

import java.util.*;
import java.util.Map;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

import org.eclipse.persistence.jaxb.JAXBContextProperties;

public class Demo {

    public static void main(String[] args) throws Exception {
        Map<String, String> properties = new HashMap<String, String>(1);
        properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, "bug405170/oxm.xml");
        JAXBContext jc = JAXBContext.newInstance(new Class[] {StringMap.class}, properties);

        StringMap stringMap = new StringMap();
        stringMap.put("a", "A");
        stringMap.put("b", "B");

        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(stringMap, System.out);
    }


}

兼容性

我已经迁移了大部分注释(我在 RI 和 Moxy 之间的行为上遇到了一些显着差异)

听到您必须更改任何注释,我感到非常惊讶。您可以针对遇到的任何问题打开错误吗?

于 2013-04-08T15:12:22.993 回答