我有一个正在序列化的类
org.springframework.integration.core.Message
进入文件如下:
示例.java
public static void receive(Message<?> message) throws IOException, MessagingException
{
XStream xStream = new XStream();
File file = new File("c:/temp/temp.xml");
FileOutputStream fileOutputStream = new FileOutputStream(file);
xStream.toXML(message,fileOutputStream);
}
UnMarshall.java
public static void main(String[] args) throws IOException, MessagingException, ClassNotFoundException
{
XStream xStream = new XStream();
File file = new File("c:/temp/temp.xml");
FileInputStream fileOutputStream = new FileInputStream(file);
Message message = (Message) xStream.fromXML(fileOutputStream);
}
如果我运行 UnMarshall.java 那么我得到以下异常:
问题
- 是否可以使用 XStream 序列化/反序列化消息对象?
如果不是,我还有什么其他选择?
线程“主”com.thoughtworks.xstream.converters.ConversionException 中的异常:无法构造类 java.lang.Class ---- 调试信息 ---- 消息:无法构造类 java.lang.Class 原因-异常:java。 lang.InstantiationException 原因消息:javax.activation.ActivationDataFlavor 类:org.springframework.integration.message.GenericMessage 所需类型:javax.activation.ActivationDataFlavor 路径:/org.springframework.integration.message.GenericMessage/payload/dh/dataContentHandler /dch/myDF 行号:14 ------------------------------- com.thoughtworks.xstream.converters.reflection。 com.thoughtworks.xstream.core 上的 ExternalizableConverter.unmarshal(ExternalizableConverter.java:110)。TreeUnmarshaller.convert(TreeUnmarshaller.java:56) at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45) at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46) at com .thoughtworks.xstream.annotations.AnnotationReflectionConverter.unmarshallField(AnnotationReflectionConverter.java:66) 在 com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:188) 在 com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter .unmarshal(AbstractReflectionConverter.java:125) 在 com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56) 在 com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller。convert(AbstractReferenceUnmarshaller.java:45) 在 com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46) 在 com.thoughtworks.xstream.annotations.AnnotationReflectionConverter.unmarshallField(AnnotationReflectionConverter.java:66) 在 com.thoughtworks .xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:188) 在 com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:125) 在 com.thoughtworks.xstream.core.TreeUnmarshaller.convert (TreeUnmarshaller.java:56) 在 com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45) 在 com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46) 在 com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:188) 在 com.thoughtworks.xstream.java:66) 在 com.thoughtworks.xstream.annotations.AnnotationReflectionConverter.unmarshallField(AnnotationReflectionConverter.java:66) 在 com.thoughtworks.xstream.converters .reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:125) 在 com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56) 在 com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45) ) 在 com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46) 在 com.thoughtworks.xstream.annotations.AnnotationReflectionConverter.unmarshallField(AnnotationReflectionConverter.java:66)在com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:188)在com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:125)在com.thoughtworks.xstream .core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56) 在 com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45) 在 com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46) ) 在 com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:188) 在 com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:125) 在 com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56) 在 com.thoughtworks.xstream.core .AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45) 在 com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46) 在 com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:117) 在com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.unmarshal(ReferenceByXPathMarshallingStrategy.java:29) 在 com.thoughtworks.xstream.XStream.unmarshal(XStream.java:846) 在 com.thoughtworks.xstream.XStream.unmarshal(XStream.java: 833)在 com.thoughtworks.xstream.XStream。fromXML(XStream.java:789) at org.springframework.integration.samples.mail.imapidle.DefaultEmailReceiverUtilService.main(DefaultEmailReceiverUtilService.java:103) 原因:java.lang.InstantiationException:java.lang 中的 javax.activation.ActivationDataFlavor。 Class.newInstance0(Class.java:340) at java.lang.Class.newInstance(Class.java:308) at com.thoughtworks.xstream.converters.reflection.ExternalizableConverter.unmarshal(ExternalizableConverter.java:80) ... 39更多的newInstance(Class.java:308) at com.thoughtworks.xstream.converters.reflection.ExternalizableConverter.unmarshal(ExternalizableConverter.java:80) ... 39 更多newInstance(Class.java:308) at com.thoughtworks.xstream.converters.reflection.ExternalizableConverter.unmarshal(ExternalizableConverter.java:80) ... 39 更多