0

I have xsd:

<xs:complexType name="RobZmenObyvateleDataType">
    <xs:annotation>
        <xs:documentation xml:lang="cs">Oprava referenčních údajů fyzické osoby v ROB.
        </xs:documentation>
    </xs:annotation>
    <xs:sequence>
        <xs:element name="AdresaPobytu" type="rob:AdresaPobytuStavType" minOccurs="0" nillable="true" />
    </xs:sequence>
</xs:complexType>

<xs:complexType name="AdresaPobytuStavType">
    <xs:annotation>
        <xs:documentation xml:lang="cs">Adresa místa pobytu v ČR včetně stavu a času poslední změny.
        </xs:documentation>
    </xs:annotation>
    <xs:simpleContent>
        <xs:extension base="AdresaPobytuType">
            <xs:attribute name="stav" type="xs:string" />
        </xs:extension>
    </xs:simpleContent>
</xs:complexType>

<xs:simpleType name="KodAdresniMistoType">
    <xs:annotation>
        <xs:documentation xml:lang="cs">Identifikátor adresního místa v RUAIN.</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:int">
        <xs:minExclusive value="-10"/>
        <xs:maxExclusive value="999999999"/>
    </xs:restriction>
</xs:simpleType>

this generate class:

public class AdresaPobytuStavType
    implements Serializable
{

    @XmlValue
    protected int value;
    @XmlAttribute(name = "stav")
    protected String stav;

}

You can see value is int and not Integer. So I add binding to cast it to Integer because I need to recognize null value:

<jaxb:bindings schemaLocation="../MyXsd.xsd">
    <jaxb:bindings node="//xs:simpleType[@name='KodAdresniMistoType']">
        <jaxb:javaType name="java.lang.Integer" />
    </jaxb:bindings>
</jaxb:bindings>

so now It look good:

@XmlValue
@XmlJavaTypeAdapter(Adapter2 .class)
protected Integer value;

problem is that is not working.

when I send xml:

<urn2:RobZmenObyvateleData>
<urn3:AdresaPobytu xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" stav="spravny"/>
</urn2:RobZmenObyvateleData>

it return 0 instead of null.

<urn2:RobZmenObyvateleData>
<urn3:AdresaPobytu stav="spravny">0</urn3:AdresaPobytu stav="spravny">
</urn2:RobZmenObyvateleData>

and this also return 0

So now how should I recognize 0 and null value ?

PS: I can not edit XSD. It is public and from other side

hudi
  • 15,555
  • 47
  • 142
  • 246
  • Couldn't you just change `value` to be of type `Integer` instead of `int` since you need to recognize `null` values? – Sam Estep Jun 29 '15 at 11:49
  • I don't believe 'int' is going to work in your case. For XMLs, wrapper types such as 'Integer' and 'Double' are your option. Also, see this - http://stackoverflow.com/questions/2254435/can-an-int-be-null-in-java. – ha9u63a7 Jun 29 '15 at 11:52
  • I have xsd from external side (I cant change it) – hudi Jun 29 '15 at 11:52
  • Is it possible to check if the attribute xsi:nil is present? – MystyxMac Jun 29 '15 at 12:01

0 Answers0