Flex Null Integer

♀尐吖头ヾ 提交于 2019-11-29 16:05:31

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

We solved this by creating a BeanProxy class which overrides setValue and getValue. In there we return NaN to the flex side if the value is a Number and null, and we return null to the Java side if it's a Double and NaN. Job done:

@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);
}

Amarghosh has the correct answer, but you'll find as you continue through your project that life is so much easier in the amf world when you apply the "everything is a string" rule. Simply a suggestion that might help a lot in the long run.

Best of luck, Jeremy

As Amarghosh answered, there is no such wrapper. As a workaround, we check the int value for -1 which equals an unassigned int value in our domain.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!