gson

Java: Using GSon incorrectly? (null pointer exception)

I'm trying to get the hits of a google search from a string of the query. public class Utils { public static int googleHits(String query) throws IOException { String googleAjax = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q="; String json = stringOfUrl(googleAjax + query); JsonObject hits = new Gson().fromJson(js...

Parsing Json Feeds with google Gson

I would like to know how to parse a json feed by items, eg. url / title / description for each item. I have had a look to the doc / api but, it didn't help me. This is what I got so far import com.google.gson.Gson; import com.google.gson.JsonObject; public class ImportSources extends Job { public void doJob() throws IOException { ...

How can I use JAXB from an unsigned applet (without signing it)?

I would like to marshall Java objects into XML and vice-versa from within an Unsigned Applet and I can't change any of the security permission/policy files, or sign the application. I seem to get a Security exception, because JAXB is attempting to access fields or constructors that it can't in the applet sandbox. The browser is runnin...

using Gson library in GWT client code

Hi, I'm currently writing a web application in java using GWT 2.0 in eclipse. I wanted to know if there is a way to use Gson library in a GWT application's client code. and if there is a way - please tell me how... Thanks! ...

Gson toJson method includes escape character when printing Strings

I'm using Gson to convert a Java object to Json. One of the object's fields holds a string containing an escaped double quote, like this: "double quote:'\"'" The toJson method returns the string as above, but I would like to print this instead: double quote:'"' Is this possible using Gson? ...

Convert Json style propertie names to Java Style CamelCase names with GSON

I'm using Gson to convert json data I get to a Java object. It works pretty well in all my tests. The problem is that our real objects have some properties named like is_online. Gson only maps them if they are named totally equal, it would be nice to have Gson convert the names to Java camel case isOnline. It seems this is possible whil...

Jackson Vs. Gson

After searching through some existing libraries for JSON, I have finally ended up with these two: Jackson Google GSon I am a bit partial towards GSON, but word on the net is that GSon suffers from certain celestial performance issue. I am continuing my comparison, in the meanwhile I was looking for help to make up my mind. ...

Is google gson running on android?

I'm playing arround with google gson for communication with my web back end at the moment. This and this older posts indicate that there are some problems with gson on android. I did some easy tests on the device already but maybe I just missed the bug. Edit I'm now parsing a lot more data. Generic lists etc. still not encountered t...

JSON feed to Java Object

Hi, I would like to know if there is a webpage/software that can "translate" a Json feed object to a Java object with attributes. For example : { 'firstName': 'John', 'lastName': 'Smith', 'address': { 'streetAddress': '21 2nd Street', 'city': 'New York' } ...

JSON array deserialization is crashing the Dalvik VM

I have some code grabbing a JSON array from my server and initially storing it as a string. This all works fine until I try and deserialize it using google's gson fromJson method. LogCat spits out the error: 04-08 17:46:35.163: ERROR/dalvikvm(401): Can't shrink stack: curFrame is in reserved area (0x41049000 0x410491c4) My code that ca...

Return type value if RunTimeException has been thrown and not catched.

I am using Gson to parse Json. What I don't understand what the return type will be if you don't catch the Runtime Exception. I was expecting it to be null, but it is not null when evaluating with a simple if statement. My code looks something like this: public X x(final String jsonString) { return gson.fromJson(jsonString, X.class)...

Unable to create json using gson

I have to make dynamic hashes, so the class example won't work since the class variables are static. I am sending in a hashmap object to toJson but it isn't working. Any suggestions on what to do? ...

Parsing JSON with GSON

I'm having some trouble with GSON, mainly deserializing from JSON to a POJO. I have the following JSON: { "events": [ { "event": { "id": 628374485, "title": "Developing for the Windows Phone" } }, { "event": ...

Is there a JSON library that can serialize Proxy objects?

Using ActiveObjects as my ORM and Gson as my JSON processor. Ran into a problem going toJson from persisted objects. The problem is that my persisted class is actually an Interface and AO is proxying that object under the hood. Here's some sample code: Venue venue = manager.get(Venue.class, id); gson.toJson(venue); Comes ...

Issue using gson with Android in Eclipse

Hi, when adding gson 1.4 to the java build path of my Android project I get the error shown below. Anybody can help? thanks [2010-05-03 18:42:07 - Atable] UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: already added: Lcom/google/gson/annotations/Expose; [2010-05-03 18:42:07 - Atable] at com.android.dx.de...

How do I install the GSON module in Java

Hi guys, I downloaded the Google JSON module a.k.a GSON. I'm ona windows system Could you tell me how to install the GSON module? I extracted the JAR into the following folder which was in my classpath: C:\Program Files\Java\jdk1.6.0_07\lib ..but when i type: import com.google.gson.Gson; import com.google.gson.GsonBuilder; I still...

Convert JSON to HashMap using Gson in Java

Hi, I'm requesting data from a server which returns data in the JSON format. Casting a HashMap into JSON when making the request wasn't hard at all but the other way seems to be a little tricky. The JSON response looks like this: { "header" : { "alerts" : [ { "AlertID" : "2", "TSExpires" : null, "Target" : "1", ...

Reflection Permission problems when using the GSON library in a applet.

I'm writing an Applet that makes some JSON-RPC calls. I'm using the Google JSON library (GSON) to cast the response JSON into a class. Thsi seems to work fine as is but when I use this code in my Applet, I'm hit with a java.lang.reflect.reflectpermission. From what I read on this thread on SO, it seems that since GSON uses Reflection, I...

How do I use Google's Gson API to deserialize JSON properly?

Hi, In short, this is a sketch of the JSON object I want to parse in JAVA: { object1: { item1: //[String | Array | Object] , item2: // ... //<> more items object2: { /* .. */ } //<> more objects } These are the POJO s I created for parsing (I'll leave out the import statements for brevi...

Java + GWT + GSON on server side

Hi everybody. I already read that there is no possibility to run GSON in GWT client code, but that it is possible to run it in server code. The latter one is which I'm trying to achive, but not getting to work. I thought any class within the com.whatever.server package has access to the whole JRE namespace including reflection. It seem...