Answer the question
In order to leave comments, you need to log in
How do I get JAXB to properly serialize a dynamically inflated nested object?
Hello. There is such an element in the scheme:
<xs:element name="CustomAttributes" minOccurs="0">
<xs:annotation>
<xs:documentation>Дополнительные атрибуты документа</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:any processContents="lax"/>
</xs:sequence>
</xs:complexType>
</xs:element>
CustomAttributes
:<xs:element name="ServiceProperties">
<xs:annotation>
<xs:documentation xml:lang="ru">МЖИ:Лицензирование предпринимательской деятельност</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:all>
<xs:element name="adress_house" minOccurs="0" type="xs:string">
<xs:annotation>
<xs:documentation xml:lang="ru">Адрес дома</xs:documentation>
</xs:annotation>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CustomAttributes", propOrder = {
"any"
})
public static class CustomAttributes {
@XmlAnyElement(lax = true)
protected Object any;
/**
* Gets the value of the any property.
*
* @return
* possible object is
* {@link Element }
* {@link Object }
*
*/
public Object getAny() {
return any;
}
/**
* Sets the value of the any property.
*
* @param value
* allowed object is
* {@link Element }
* {@link Object }
*
*/
public void setAny(Object value) {
this.any = value;
}
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
})
@XmlRootElement(name = "ServiceProperties")
public class ServiceProperties {
@XmlElement(name = "adress_house")
protected String adressHouse;
/**
* Gets the value of the adressHouse property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getAdressHouse() {
return adressHouse;
}
/**
* Sets the value of the adressHouse property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setAdressHouse(String value) {
this.adressHouse = value;
}
}
<CustomAttributes>
<ServiceProperties>
<adressHouse >123</adressHouse >
</ServiceProperties>
</CustomAttributes>
ServiceProperties serviceProperties = new ServiceProperties();
serviceProperties.setAdressHouse("123");
customAttributes.setAny(serviceProperties );
toString()
( ) on that object serviceProperties
. JAXBElement
, but also does not help. Is there any normal solution? serviceProperties
, and then throw it into the method setAny()
; but this is some kind of crutch solution)
Answer the question
In order to leave comments, you need to log in
Everything is working. It turned out that when creating the context, it was necessary to register the package in which lies ServiceProperties
:
Also, in order to avoid problems with namespaces, I transferred a file package-info.java
from the main package to this package. The file has the following content:
@javax.xml.bind.annotation.XmlSchema(namespace = "http://firma.ru/schema/v6_1/", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package ru.my-firm.app.my-project.jaxbobjects;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question