i'm stuck with Thrift about data types.
Now when i map and Integer value to a thrift generated bean, i'm using i32 type in the idl definition.
class MyBean {
Integer i = null;
}
struct TMyBean {
1: i32 i;
}
The problem is that in TMyBean generated bean, the i var is an int primitive type, than it's putting 0 as the default value, and for me 0 it's a valid value.
I've tried to put the optional keyword in the idl file, but things are not changing, it's always int.
How i've to handle this situation? i need i to accept a null value in TMyBean i var.
Thanks, Phaedra..
The optional keyword was the right choice.
To test, whether or not a particular optional field is set or not, use the isset flags:
struct MyBean {
1: i32 IntValue
}
gives
public class MyBean implements org.apache.thrift.TBase<MyBean, MyBean._Fields>, java.io.Serializable, Cloneable, Comparable<MyBean> {
// ... lots of other code omitted ...
// isset id assignments
private static final int __INTVALUE_ISSET_ID = 0;
private byte __isset_bitfield = 0;
// ... lots of other code omitted ...
/** Returns true if field IntValue is set (has been assigned a value) and false otherwise */
public boolean isSetIntValue() {
return EncodingUtils.testBit(__isset_bitfield, __INTVALUE_ISSET_ID);
}
public void setIntValueIsSet(boolean value) {
__isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __INTVALUE_ISSET_ID, value);
}
// ... even more code omitted ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With