Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ParseJSON - com.google.gson.JsonNull cannot be cast to com.google.gson.JsonObject #282

Closed
ghost opened this issue Mar 9, 2017 · 3 comments

Comments

@ghost
Copy link

ghost commented Mar 9, 2017

Hi, I need consume my GeoJSON which is represent route from my service. GeoJSON looks like this:
http://pastebin.com/GJWYNkAq

Here is my function for display GeoJSON in OsmDroid MapView (map variable):

public void viewRoute(String geoJson) {
    KmlDocument kmlDocument = new KmlDocument();
    kmlDocument.parseGeoJSON(geoJson); //application is crashed here
    FolderOverlay myOverLay = (FolderOverlay) kmlDocument.mKmlRoot.buildOverlay(map, null, null, kmlDocument);
    map.getOverlays().add(myOverLay);
    map.invalidate();
}

For consume my Rest api I am using OkHTTP client, after recieved GeoJSON in string, I pass it into function viewRoute, and I got following issues:

java.lang.ClassCastException: com.google.gson.JsonNull cannot be cast to com.google.gson.JsonObject at com.google.gson.JsonObject.getAsJsonObject(JsonObject.java:191) at org.osmdroid.bonuspack.kml.KmlPlacemark.(KmlPlacemark.java:89) at org.osmdroid.bonuspack.kml.KmlFeature.parseGeoJSON(KmlFeature.java:237) at org.osmdroid.bonuspack.kml.KmlFolder.(KmlFolder.java:62) at org.osmdroid.bonuspack.kml.KmlFeature.parseGeoJSON(KmlFeature.java:235) at org.osmdroid.bonuspack.kml.KmlDocument.parseGeoJSON(KmlDocument.java:1097) at org.osmdroid.bonuspack.kml.KmlDocument.parseGeoJSON(KmlDocument.java:1112) at bachelor.vsb.martin.osmdroidclient.MainActivity.viewRoute(MainActivity.java:137) at bachelor.vsb.martin.osmdroidclient.MainActivity$1.onResponse(MainActivity.java:127) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:135) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761)

@MKergall
Copy link
Owner

MKergall commented Mar 9, 2017

"geometry": null is not supported. I never noticed it was part of the GeoJSON spec!

I will add support for that - probably by ignoring such Features.
In the meantime, just remove this Feature from your file and it will work fine.

@MKergall
Copy link
Owner

MKergall commented Mar 9, 2017

#2cb85bc pushed. It now supports your file.

At saving, "geometry:null" is not in the file produced. To be investigated.

@MKergall
Copy link
Owner

Similar issue will occur with "properties:null".

The spec says: "The value of the properties member is an object (any JSON object or a JSON null value)",
but JSON null value is not supported yet.

MKergall added a commit that referenced this issue Mar 10, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant