Is there an easy way to return data to web service clients in JSON using java? I\'m fine with servlets, spring, etc.
We have been using Flexjson for converting Java objects to JSON and have found it very easy to use. http://flexjson.sourceforge.net
Here are some examples:
public String searchCars() {
List cars = carsService.getCars(manufacturerId);
return new JSONSerializer().serialize(cars);
}
It has some cool features such as deepSerialize to send the entire graph and it doesn't break with bi directional relationships.
new JSONSerializer().deepSerialize(user);
Formatting dates on the server side is often handy too
new JSONSerializer().transform(
new DateTransformer("dd/MM/yyyy"),"startDate","endDate"
).serialize(contract);