Исключение связывания при чтении XML из пространства имен - PullRequest
0 голосов
/ 09 апреля 2020

Я пытаюсь упорядочить объект и отправить его в 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">

Класси c способ сделать это на самом деле работает

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

1 Ответ

0 голосов
/ 10 апреля 2020

Установка классов для ограничения решена проблема

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