Flex Null Integer

前端 未结 4 770
無奈伤痛
無奈伤痛 2020-12-21 16:40

I take data from Java to Flex by AMF (BlazeDS)

In java side object has Integer field. So it can be null.

In Flex side object is int. So null values are deser

4条回答
  •  隐瞒了意图╮
    2020-12-21 17:24

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

提交回复
热议问题