Using Gson to map Google Maps API's json response object to java

691 views
Skip to first unread message

Fritz

unread,
Aug 2, 2008, 6:29:55 AM8/2/08
to google-gson
hi!

well i'm trying to map the json object of google maps to a java
object! this works fine by creating an Location class which holds an
AddressDetails class whereas the object holds a Country class

public class Location {

public Location() { }

String id = "1";
String address = "zösenberg 83";
AddressDetails addressDetails = new AddressDetails(new Country(new
AdministrativeArea(new Locality())));
}

package json;

public class AddressDetails {

public AddressDetails(Country country) {
this.country = country;
}

Country country;

}

package json;

public class Country {

public Country(AdministrativeArea administrativeArea) {
this.administrativeArea = administrativeArea;
}

String CountryNameCode = "US";
AdministrativeArea administrativeArea;

}


and so on and so on.....

this way and the possibility to create inner classes also make the
hole thing not more elegant!

does anybody have a hint, clue etc for me to solve this issue

cu fritz

Inderjeet Singh

unread,
Aug 3, 2008, 3:00:00 AM8/3/08
to googl...@googlegroups.com
Hi,

As I understand it, what you really want is an automatic way of generating Java classes from Json.
This is a hard problem since there is usually no schema for Json, so it is kind of hard to figure out what class to generate.

However, there is some work going on in defining a Json schemas (see http://groups.google.com/group/json-schema/web/json-schema-proposal---second-draft).
If you have that, then it is possible to write a tool that can automatically generate Java classes out of that. We can possibly even modify Gson to
do so, see the bug: http://code.google.com/p/google-gson/issues/detail?id=17

Until then, you are better off writing a set of Java classes that will match to Google map Json (using Gson).
I would encourage to even open-source that library for the benefit of others.

We can host it under Gson project even, as third-party contributions. Or if you create a new project, we can link it from Gson.

Inder

Friedrich Roman Gaschler

unread,
Aug 3, 2008, 5:49:51 AM8/3/08
to googl...@googlegroups.com
hihi! 

cool idea ! i will try to get somthing that works for my needs !

thanks for your help 

fritz
Reply all
Reply to author
Forward
0 new messages