Flex Null Integer

I am taking data from Java to Flex using AMF (BlazeDS)

There is an Integer field in the java side object. Therefore, it can be zero.

The Flex side object has an int. Thus, null values ​​are deserialized as 0.

This is not what I want, I want to see if it is 0 or zero.

Is there such a shell (Integer in Java) for Flex? Thanks

+2
source share
4 answers

As far as I can tell, there is no such shell. You can write one that assigns NaN an int if the argument to the constructor is null

+4
source

We solved this by creating a BeanProxy class that overrides setValue and getValue. There we return NaN to the flex side if the value is Number and null, and we return null to the Java side if it is Double and NaN. The task:

  @Override
 public void setValue (Object instance, String propertyName, Object value) {
     if ((value instanceof Double)) {
         Double doubleValue = (Double) value;
         if (doubleValue! = null && doubleValue.isNaN ()) {
             super.setValue (instance, propertyName, null);
         }
     } else {
           super.setValue (instance, propertyName, value);
         }
 }

 @Override
 public Object getValue (Object obj, String propertyName) {
     final Class classType = super.getType (obj, propertyName);
     if (isNumber (classType) && super.getValue (obj, propertyName) == null) {
         return Double.NaN;
     }
     return super.getValue (obj, propertyName);
 }
+3
source

Amarghosh has the correct answer, but you will find that continuing your project makes life much easier in the amf world when you apply the “everything is a string” rule. Just an offer that can help in the long run.

Best of luck, Jeremy.

+1
source

As Amargosh replied, there is no such wrapper. As a workaround, we check the int value for -1, which is equal to the unassigned int value in our domain.

0
source

Source: https://habr.com/ru/post/1339191/


All Articles