Code Monkey home page Code Monkey logo

Comments (5)

srtvprateek avatar srtvprateek commented on June 13, 2024

hey @ReggieLei, can you share more details & steps to reproduce the issue.

from pluto.

ReggieLei avatar ReggieLei commented on June 13, 2024

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

from pluto.

srtvprateek avatar srtvprateek commented on June 13, 2024

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.

from pluto.

ReggieLei avatar ReggieLei commented on June 13, 2024

Maybe you can try (https://github.com/alibaba/fastjson2)

or extends to rewrite TypeAdapter for Gson
public class MapTypeAdapter extends TypeAdapter {

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(){}.getType(),new MapTypeAdapter()).create();
return gson.fromJson(strJson, new TypeToken() {
}.getType());
}

String json = "{"identifier":"18111111111","opType":1,"platform":0}";
Map<String, Object> map = new MyType<Map<String, Object>>().gsonToMap(json);

from pluto.

srtvprateek avatar srtvprateek commented on June 13, 2024

sure @ReggieLei,
thanks for the suggestion, will look into this

from pluto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.