pluto
                                
                                
                                
                                    pluto copied to clipboard
                            
                            
                            
                        An Int is converted to a double
com.plutolib.plugins:network:2.0.3 response -> body Int is converted to a double ....
hey @ReggieLei, can you share more details & steps to reproduce the issue.
Right back [{ "deviceId": "905436c790da4766a1c8e7d213f6a765", "deviceCode": "NIC1C2206022", "fourGOnline": 0, "wifiOnline": 1, "bluetoothOnline": 1, "wifiStrength": 18, "fourGStrength": 0, "pileStatus": -1, "isAdmin": 1, "isForbid": 1, }]
pluto catch back RESPONSE *** Body *** [ { "deviceId": "905436c790da4766a1c8e7d213f6a765", "deviceCode": "NIC1C2206022", "fourGOnline": 0.0, "wifiOnline": 1.0, "bluetoothOnline": 1.0, "wifiStrength": 18.0, "fourGStrength": 0.0, "pileStatus": -1.0, "isAdmin": 1.0, "isForbid": 1.0, } ]
report generated by Pluto (https://plutolib.com)
All Int is converted to double
thanks for posting the issue @ReggieLei .
JSON is a type agnostic representation. As per official JSON docs
JSON does not have distinct types for integers and floating-point values. Therefore, the presence or absence of a decimal point is not enough to distinguish between integers and non-integers. https://json-schema.org/understanding-json-schema/reference/numeric.html
That said, we ll definitely look into it, if we can differentiate between Integer & Double.
Maybe you can try (https://github.com/alibaba/fastjson2)
or extends to rewrite TypeAdapter for Gson public class MapTypeAdapter extends TypeAdapter<Object> {
private final TypeAdapter<Object> delegate = new Gson().getAdapter(Object.class);
@Override
public Object read(JsonReader in) throws IOException {
    JsonToken token = in.peek();
    switch (token) {
        case BEGIN_ARRAY:
            List<Object> list = new ArrayList<>();
            in.beginArray();
            while (in.hasNext()) {
                list.add(read(in));
            }
            in.endArray();
            return list;
        case BEGIN_OBJECT:
            Map<String, Object> map = new LinkedTreeMap<>();
            in.beginObject();
            while (in.hasNext()) {
                map.put(in.nextName(), read(in));
            }
            in.endObject();
            return map;
            
        case STRING:
            return in.nextString();
        case NUMBER:
            double dbNum = in.nextDouble();
            if (dbNum > Long.MAX_VALUE) {
                return String.valueOf(dbNum);
            }
            long lngNum = (long) dbNum;
            if (dbNum == lngNum) {
                return String.valueOf(lngNum);
            } else {
                return String.valueOf(dbNum);
            }
        case BOOLEAN:
            return in.nextBoolean();
        case NULL:
            in.nextNull();
            return null;
        default:
            throw new IllegalStateException();
    }
}
@Override
public void write(JsonWriter out, Object value) throws IOException {
    delegate.write(out,value);
}
} public T gsonToMap(String strJson) { Gson gson = new GsonBuilder() .registerTypeAdapter(new TypeToken<T>(){}.getType(),new MapTypeAdapter()).create(); return gson.fromJson(strJson, new TypeToken<T>() { }.getType()); }
String json = "{"identifier":"18111111111","opType":1,"platform":0}"; Map<String, Object> map = new MyType<Map<String, Object>>().gsonToMap(json);
sure @ReggieLei, thanks for the suggestion, will look into this