JsonValue checkedTypes limitation reasoning

Hey,
I just realized that the JsonValue Type only allows a subselection of the primitive types. Is this a intentional discouragement to use types like float or byte as the underlying implementation uses double/integer anyway? Or might this be changed in the future?

    protected static boolean checkType(Object item) {
        return item == null
            || item instanceof String
            || item instanceof Integer
            || item instanceof Long
            || item instanceof Double
            || item instanceof Boolean
            || item instanceof JsonObject
            || item instanceof JsonArray;
    }

@Kademlia the main reason why we did pick those is that JSON itself doesn’t have such a rich data type set and it gets harder to go back to the right datatype on decoding. JSON Only knows “numbers”, so floats are subsumed by doubles and so are integers through longs. And since JSON only knows a String type, you can fit a char into a single-char string.

Does that help with the reasoning or is there a specific use case which you don’t see covered with this approach?

That was fast! Thank you, that’s what i was expecting.

1 Like