我正在尝试将对象编组并将其发送给JMS。
我在做什么错?

QName qName = new QName("http://schema.gspt.net/EventCanonical/1.0","OrderType");
JAXBElement<OrderType> jaxbElement = new JAXBElement( qName, OrderType.class,orderType);
jaxb2Marshaller.createMarshaller().marshal(jaxbElement,sw);

javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.internal.SAXException2: com.radial.notification.event.OrderType is not known to this
context


这是XML中的名称空间

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://schema.gspt.net/EventCanonical/1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://schema.gspt.net/EventCanonical/1.0" elementFormDefault="qualified"
attributeFormDefault="unqualified">


实际起作用的经典方法

JAXBContext jaxbContext = JAXBContext.newInstance(OrderType.class);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.marshal(orderType, sw);

最佳答案

将类设置为绑定可解决问题

Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(OrderType.class)

08-18 03:29