[jibx-users] serialization of choice containing int, long so on

2015-11-11 Thread Sven Krause
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.


instead of
0

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

...



where choice.setInteger(1);will be serialized as

...

1



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


Re: [jibx-users] serialization of choice containing int, long so on

2015-11-25 Thread Sven Krause
Hi there,

any ideas for the issue? Should I file a bug? Or should I attach a POC
source package?

Cheers,
Sven

> 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.
>
> 
> instead of
> 0
>
> 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
> 
> ...
> 
> 
>
> where choice.setInteger(1);will be serialized as
> 
> ...
> 
> 1
> 
> 
>
> 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

--
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741551=/4140___
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users