Kong / unirest-java

Unirest in Java: Simplified, lightweight HTTP client library.
http://kong.github.io/unirest-java/
MIT License
2.59k stars 593 forks source link

Parse json incorrectly #366

Closed zjffdu closed 4 years ago

zjffdu commented 4 years ago

Describe the bug

Here's the code I write,

    JSONObject jsonObject = new JSONObject("{\"status\":\"OK\",\"message\":\"hive_1597818501335\"}");
    System.out.println(jsonObject);

But the output is unexpected

{"members":{}}

It is very weird, I don't know how does members come from.

To Reproduce The the sample code above.

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Environmental Data:

Additional context Add any other context about the problem here.

ryber commented 4 years ago

I added a test, it works just fine: https://github.com/Kong/unirest-java/commit/4aa7c5be4e0d664e31e67f518bd576565784645b

Do you maybe have an old version of Gson on your claspath?

zjffdu commented 4 years ago

Thanks @ryber , you are right this is due to I have another gson on my classpath.

ryber commented 4 years ago

Can I ask, what version are you using? It's possible I could make Unirest more backwards compatible

zjffdu commented 4 years ago

I use gson 2.2

ryber commented 4 years ago

Oh, yea, that's way too old, I'm kind of surprised that you don't get a classnotfound exception