ambient-weather / api-docs

AmbientWeather.net API Documentation
64 stars 42 forks source link

24hourrainin JSON parameter is problematic in Java #9

Closed mhilbush closed 5 years ago

mhilbush commented 5 years ago

Looking at the device data soecs here... https://github.com/ambient-weather/api-docs/wiki/Device-Data-Specs

When using Gson's fromJson method to parse the device data JSON, the class fields must have the same name as the name in the JSON. In the case of 24hourrain, Java class fields cannot start with a number.

owise1 commented 5 years ago

Were you able to find a workaround for this? I think it's too late to change for this version of the API

mhilbush commented 5 years ago

I figured v1 of the API could not be changed at this point. I haven't looked for a workaround yet. Definitely not if using the the fromJson method. Sticking with Gson (since it's the standard JSON package in openHAB), the JsonReader class looks the most promising. I just haven't had a chance to try it out yet.

lrosenman commented 5 years ago

I had brought this up in Beta and was rejected.

mhilbush commented 5 years ago

and was rejected

Why? It's a real issue (at least for Java implementations).

lrosenman commented 5 years ago

It is for go as well. Go look at the earlier issues. @owise1 didn't want to change it.

owise1 commented 5 years ago

Really? I'm not sure why I would have had an opinion about this. It may have been an oversight.

mhilbush commented 5 years ago

Just wanted to close this out. I was able to confirm that I can extract the 24hourrain element (albeit inefficiently) using Gson's JsonReader object.

I would recommend in the future to avoid creating JSON names that start with numbers.

owise1 commented 5 years ago

sorry for the inconvenience and thanks for your feedback.