powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / jersey клиент пасинг XML
2 сообщений из 2, страница 1 из 1
jersey клиент пасинг XML
    #39034019
denis111111
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Добрий день.

Делаю парсинг такой XML:

Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
<?xml version="1.0" encoding="UTF-8"?>
<response>
	<customfields>
		<customfield>
			<privateName>privatename</privateName>
			<publicName>tetet</publicName>
			<displayToUser>1</displayToUser>
			<fieldType>text</fieldType>
			<customFieldId>privatename</customFieldId>
		</customfield>
	</customfields>
</response>



Классы для мапинга:
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "response")
public class Response<T> {

    @XmlAnyElement(lax = true)
    private T content;

    public T getContent() {
        return content;
    }

    public void setContent(T content) {
        this.content = content;
    }

}


Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "customfields")
public class Customfields {

    @XmlElement(name = "customfield")
    private List<Customfield> customfields;

    public List<Customfield> getCustomfields() {
        return customfields;
    }

    public void setCustomfields(List<Customfield> customfields) {
        this.customfields = customfields;
    }

}


Код: java
1.
2.
3.
4.
5.
6.
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "customfield")
public class Customfield {

    private String customFieldId;
    private String privateName;



Шлю запрос так:
Код: java
1.
Response<Customfields> response = requestBuilder.post(MediaType.APPLICATION_XML, new GenericType<Response<Customfields>>(){}, customfield);



В результате мне выдает ошибку
com.sun.org.apache.xerces.internal.dom.ElementNSImpl cannot be cast to com.savvymoney.mailing.xmlwrapper.Customfields
java.lang.ClassCastException

Дело в том, что через JAX-B, я без проблем это делал..., Просто передавал в JAXBContext - Response.class и Customfields.class
Не понимаю почему в jersey сделали не так же...
...
Рейтинг: 0 / 0
jersey клиент пасинг XML
    #39034556
z3r9
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Вот так нужно делать:
Код: java
1.
2.
3.
JAXBContext jaxbContext = JAXBContext.newInstance(Customfields.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
Customfields customfields = (Customfields) unmarshaller.unmarshal(content);
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / jersey клиент пасинг XML
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]