Hi,

I've generated data classes based on a predefined xsd. One of the types
defines a choice of various base types. So far so good. But If the data
type is a atomar java data type (int, long, byte etc) and the value is
'0', the xml element created while serialization remains empty.

<value />
instead of
<value><integer>0</integer><value>

The generator created a choice class wrapping the types like:

public class TYPEValue {
    private Choice choice;
    public get/setChoice(...);

    public static class Choice {
        private int choiceSelect = -1;
        private static final int LONG_CHOICE = 0;
        private static final int INTEGER_CHOICE = 1;
        ...
        private static final int UTF8_STRING_CHOICE = 12;

        private long _long;
        private int _integer;
        ...
        private String UTF8String;
        public boolean ifInteger() {
            return  choiceSelect ==  INTEGER_CHOICE;
        }
       
        public void setInteger(int _integer) {
            setChoiceSelect(INTEGER_CHOICE);
            this._integer = _integer;
        }
       
    }
}

Unfortunately will be neither the choice nor the value serialized, if
the atomar java types (int, long, byte, short etc) '0'.

TYPEValue type = new TYPEValue();
TYPEValue.Choice choice = new TYPEValue.Choice();
choice.setInteger(0);
type.setChoice(choice);

will be serialized as
<parent>
    ...
    <value />
</parent>

where choice.setInteger(1);will be serialized as
<parent>
    ...
    <value>
        <integer>1</integer>
    </value>
</parent>

With the consequence, that the deserialization loses the choice
information too. That means the choice member of the TYPEValue object
stays null - what makes sense from the xml information set.


I tried to override the empty element by using own
serializer/deserializer, without success - the xml element remains
without choice and int value. So I decompiled the - by the binding
compiler created class TYPEValue$Choice. Surprise:
public static void JiBX_binding_marshal_1_0(ext arg1, MarshallingContext
arg2) throws JiBXException {
            arg2.pushObject(arg1);
            arg2;
            ...

            if(!arg1.ifInteger()) goto _L4; else goto _L3
_L3:
            3;
            "integer";
            int i = arg1.getInteger();
            i;
            _*if(i != 0) goto _L6; else goto _L5*_
_L5:
            JVM INSTR pop ;
            JVM INSTR pop ;
            JVM INSTR pop ;
              goto _L4
_L6:
            JiBXConverter.writeInt(); // my customized serializer
            element();
_L4:
            ....

The choice value will be inspected and skipped explicit for atomar java
data types. May I override this behaviour? Is this a bug?

Thanks in advance
Sven
------------------------------------------------------------------------------
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to