如何克服;Clob是一个接口,JAXB可以';t处理接口“;问题

如何克服;Clob是一个接口,JAXB可以';t处理接口“;问题,jaxb,Jaxb,我正在创建一个jaxbcontext新实例,将DO作为类传递。我的DO包含java.sql.clob作为字段之一。 此clob字段在创建新实例时正在创建问题。将错误视为 捕获clob时发生异常 com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 3 counts of IllegalAnnotationExceptions java.sql.Clob is an interface, and JAXB can't handle int

我正在创建一个jaxbcontext新实例,将DO作为类传递。我的DO包含java.sql.clob作为字段之一。 此clob字段在创建新实例时正在创建问题。将错误视为 捕获clob时发生异常

com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 3 counts of IllegalAnnotationExceptions
java.sql.Clob is an interface, and JAXB can't handle interfaces.
    this problem is related to the following location:
        at java.sql.Clob
        at public java.sql.Clob com.data.subscriber.SubscriberProvTransDO.getXmlString()
        at com.data.subscriber.SubscriberProvTransDO
The type of the getter is java.io.InputStream but that of the setter is long. They have to be the same.
    this problem is related to the following location:
        at public abstract java.io.InputStream java.sql.Clob.getAsciiStream() throws java.sql.SQLException
        at java.sql.Clob
        at public java.sql.Clob com.data.subscriber.SubscriberProvTransDO.getXmlString()
        at com.data.subscriber.SubscriberProvTransDO
    this problem is related to the following location:
        at public abstract java.io.OutputStream java.sql.Clob.setAsciiStream(long) throws java.sql.SQLException
        at java.sql.Clob
        at public java.sql.Clob com.data.subscriber.SubscriberProvTransDO.getXmlString()
        at com.data.subscriber.SubscriberProvTransDO
The type of the getter is java.io.Reader but that of the setter is long. They have to be the same.
    this problem is related to the following location:
        at public abstract java.io.Reader java.sql.Clob.getCharacterStream() throws java.sql.SQLException
        at java.sql.Clob
        at public java.sql.Clob com.data.subscriber.SubscriberProvTransDO.getXmlString()
        at com.data.subscriber.SubscriberProvTransDO
    this problem is related to the following location:
        at public abstract java.io.Writer java.sql.Clob.setCharacterStream(long) throws java.sql.SQLException
        at java.sql.Clob
        at public java.sql.Clob com.data.subscriber.SubscriberProvTransDO.getXmlString()
        at com.data.subscriber.SubscriberProvTransDO

    at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:66)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:389)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:236)
    at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:76)
    at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:55)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:618)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:210)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:368)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
    at com.business.system.handler.EventProcessorHandler.insertFailure(EventProcessorHandler.java:286)
    at com.business.system.handler.EventProcessorHandler.processRequest(EventProcessorHandler.java:184)
    at com.business.system.EventProcessorBean.onMessage(EventProcessorBean.java:51)
    at com.ibm.ejs.container.MessageEndpointHandler.invokeMdbMethod(MessageEndpointHandler.java:1086)
    at com.ibm.ejs.container.MessageEndpointHandler.invoke(MessageEndpointHandler.java:773)
    at $Proxy6.onMessage(Unknown Source)
    at com.ibm.ws.sib.api.jmsra.impl.JmsJcaEndpointInvokerImpl.invokeEndpoint(JmsJcaEndpointInvokerImpl.java:201)
    at com.ibm.ws.sib.ra.inbound.impl.SibRaDispatcher.dispatch(SibRaDispatcher.java:768)
    at com.ibm.ws.sib.ra.inbound.impl.SibRaSingleProcessListener$SibRaWork.run(SibRaSingleProcessListener.java:584)
    at com.ibm.ejs.j2c.work.WorkProxy.run(WorkProxy.java:419)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:3次illegalannotationException计数
Clob是一个接口,JAXB不能处理接口。
此问题与以下位置有关:
在java.sql.Clob
在public java.sql.Clob com.data.subscriber.SubscriberProvTransDO.getXmlString()上
在com.data.subscriber.SubscriberProvTransDO
getter的类型是java.io.InputStream,但setter的类型是long。它们必须是一样的。
此问题与以下位置有关:
在公共抽象java.io.InputStream中,java.sql.Clob.getAsciStream()抛出java.sql.SQLException
在java.sql.Clob
在public java.sql.Clob com.data.subscriber.SubscriberProvTransDO.getXmlString()上
在com.data.subscriber.SubscriberProvTransDO
此问题与以下位置有关:
在公共抽象java.io.OutputStream中,java.sql.Clob.setAscistream(long)抛出java.sql.SQLException
在java.sql.Clob
在public java.sql.Clob com.data.subscriber.SubscriberProvTransDO.getXmlString()上
在com.data.subscriber.SubscriberProvTransDO
getter的类型是java.io.Reader,而setter的类型是long。它们必须是一样的。
此问题与以下位置有关:
在公共抽象中,java.io.Reader java.sql.Clob.getCharacterStream()抛出java.sql.SQLException
在java.sql.Clob
在public java.sql.Clob com.data.subscriber.SubscriberProvTransDO.getXmlString()上
在com.data.subscriber.SubscriberProvTransDO
此问题与以下位置有关:
在公共抽象中,java.io.Writer java.sql.Clob.setCharacterStream(long)抛出java.sql.SQLException
在java.sql.Clob
在public java.sql.Clob com.data.subscriber.SubscriberProvTransDO.getXmlString()上
在com.data.subscriber.SubscriberProvTransDO
位于com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:66)
位于com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:389)
位于com.sun.xml.bind.v2.runtime.JAXBContextImpl(JAXBContextImpl.java:236)
位于com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:76)
位于com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:55)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)中
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中
位于java.lang.reflect.Method.invoke(Method.java:618)
位于javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:210)
位于javax.xml.bind.ContextFinder.find(ContextFinder.java:368)
位于javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
位于javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
位于com.business.system.handler.EventProcessorHandler.insertFailure(EventProcessorHandler.java:286)
位于com.business.system.handler.EventProcessorHandler.processRequest(EventProcessorHandler.java:184)
位于com.business.system.EventProcessorBean.onMessage(EventProcessorBean.java:51)
位于com.ibm.ejs.container.MessageEndpointHandler.invokeMdbMethod(MessageEndpointHandler.java:1086)
位于com.ibm.ejs.container.MessageEndpointHandler.invoke(MessageEndpointHandler.java:773)
在$Proxy6.onMessage(未知来源)
位于com.ibm.ws.sib.api.jmsra.impl.JmsJcaEndpointInvokerImpl.invokeEndpoint(JmsJcaEndpointInvokerImpl.java:201)
位于com.ibm.ws.sib.ra.inbound.impl.SibRaDispatcher.dispatch(SibRaDispatcher.java:768)
位于com.ibm.ws.sib.ra.inbound.impl.SibRaSingleProcessListener$SibRaWork.run(SibRaSingleProcessListener.java:584)
位于com.ibm.ejs.j2c.work.WorkProxy.run(WorkProxy.java:419)
位于com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)

对于这个用例,您可以使用
XmlAdapter
。XML适配器将不可映射对象
java.sql.Clob
转换为可映射对象,例如
String

ClobAdapter

import java.sql.Clob;

import javax.xml.bind.annotation.adapters.XmlAdapter;

public class ClobAdapter extends XmlAdapter<String, Clob> {

    @Override
    public Clob unmarshal(String v) throws Exception {
        // Convert String to Clob
    }

    @Override
    public String marshal(Clob v) throws Exception {
        // Convert Clob to String
    }

}
演示

import javax.xml.bind.JAXBContext;

public class Demo {

    public static void main(String[] args) throws Exception {
        JAXBContext jc = JAXBContext.newInstance(Root.class);
    }
}
了解更多信息


谢谢Blaise,我以前试过这个,但没有帮到我,并且给出了与上述相同的错误。@ABC-你能试一下我答案中的简短演示,如果你看到异常,请告诉我吗?嘿,演示对我有用。现在我很困惑为什么它不适用于我的projectI,它错误地放置了注释,因此出现了错误。它现在工作正常了1.谢谢你的帮助。
import javax.xml.bind.JAXBContext;

public class Demo {

    public static void main(String[] args) throws Exception {
        JAXBContext jc = JAXBContext.newInstance(Root.class);
    }
}