Имеется XML:
<getNewLNNumRangeResponse xmlns="http://www.fss.ru/integration/types/eln/mo/v01" xmlns:ns2="http://www.fss.ru/integration/types/eln/v01" xmlns:ns3="http://www.fss.ru/integration/types/eln/ins/v01" xmlns:ns4="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:ns5="http://www.fss.ru/integration/types/fault/v01" xmlns:ns6="http://www.fss.ru/integration/types/common/v01">
<ns2:requestId>LNNUMMO_1024201477520_2022_05_26_00072</ns2:requestId>
<ns2:status>1</ns2:status>
<ns2:mess>OK</ns2:mess>
<data>
<ns2:lnCode>900000672560</ns2:lnCode>
<ns2:lnCode>900000672561</ns2:lnCode>
<ns2:lnCode>900000672562</ns2:lnCode>
</data>
</getNewLNNumRangeResponse>
Пытаюсь размаршалить в модели при помощи JAXB. Модели:
@XmlRootElement(name = "getNewLNNumRangeResponse")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"data"
})
public class GetNewLNNumRangeResponse
extends WSResult
{
@XmlElement(required = true, nillable = true)
protected LnCodeList data;
/**
* Gets the value of the data property.
*
* @return
* possible object is
* {@link LnCodeList }
*
*/
public LnCodeList getData() {
return data;
}
/**
* Sets the value of the data property.
*
* @param value
* allowed object is
* {@link LnCodeList }
*
*/
public void setData(LnCodeList value) {
this.data = value;
}
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "LnCodeList", propOrder = {
"lnCode"
})
public class LnCodeList {
@XmlElement(required = true)
protected List<String> lnCode;
/**
* Gets the value of the lnCode property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the lnCode property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getLnCode().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link String }
*
*
*/
public List<String> getLnCode() {
if (lnCode == null) {
lnCode = new ArrayList<String>();
}
return this.lnCode;
}
}
Собственно пытаюсь выгрузить список, а он пустой:
List<String> lnCode = getNewLNNumRangeResponse.getData().getLnCode();
Проблема как мне кажется в аннотациях, чего-то не хватает. Не пойму чего только.
Обновление. В XML содержится много другой информации, цифровая подпись. Расшарить полностью документ не получится.
В модель попадает все кроме блока data. Он имеет значение null.
Обновление.
По совету ulxanxv, Добавил @XmlJavaAdapterType
на поле и смог получить значение, но выглядит как велосипед не понятно почему он не подставляет сразу как нужно...
public class XmlAdapterTest extends XmlAdapter<Object, LnCodeList> {
public Object marshal(LnCodeList boundType) throws Exception {
return (LnCodeList) boundType;
}
public LnCodeList unmarshal(Object valueType) throws Exception {
LnCodeList lnCodeList = new LnCodeList();
List<String> draft = new ArrayList<String>();
ElementNSImpl ns = (ElementNSImpl) valueType;
for(int index = 0; index < ns.getChildNodes().getLength(); index++) {
Node item = ns.getChildNodes().item(index);
draft.add(item.getTextContent());
}
lnCodeList.setLnCode(draft);
return lnCodeList;
}
}
@XmlJavaTypeAdapter(XmlAdapterTest.class)
@XmlElement(required = true, nillable = true)
protected LnCodeList data;
Не знаю можно ли это считать ответом, но работает.
required = true, nillable = true
. Как оно может быть обязательно и не обязательно одновременноnamespace
:@XmlElement(namespace="http://www.fss.ru/integration/types/eln/v01") protected List<String> lnCode;
?<ns2:lnCode>
и<lnCode>
- это как бы разные теги