Hi,

there are a couple of numeric types missing from the NumberType JSon serialization helper like BigDecimal, BigInteger and Byte.

I just added BigDecimal. I need to use the string format to avoid rounding and truncation -> take a look at the Number JDK 1.0 (!) class (is this safe???)

public void toJSON( Object value, JSONWriter json ) throws JSONException
    {
        Number number = (Number) value;
        if( type.isClass( Integer.class ) )
        {
            json.value(number.longValue());
        }
...
        else if( type.isClass( BigDecimal.class ) )
        {
            json.value(((BigDecimal)value).toPlainString());
        }
    }

    public Object fromJSON( Object json, Module module )
    {
        if( type.isClass( BigDecimal.class ) )
        {
            return new BigDecimal((String) json);
        }
        
        Number number = (Number) json;

        if( type.isClass( Integer.class ) )
        {
            return number.intValue();
        }
...
        else if( type.isClass( Short.class ) )
        {
            return number.shortValue();
        }
throw new IllegalStateException( "Unknown number type:" + type );
    }


WDYT ?

cheers,

phil
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to