GSON – Date format

I’m trying to have a custom date format in Gson output, but .setDateFormat(DateFormat.FULL) doesn’t seem to work and it the same with .registerTypeAdapter(Date.class, new DateSerializer()). It’s like Gson doesn’t care about the object “Date” and print it in its way. How can I change that? Thanks EDIT: @Entity public class AdviceSheet { public Date lastModif; … Read more

Converting JSON data to Java object

I want to be able to access properties from a JSON string within my Java action method. The string is available by simply saying myJsonString = object.getJson(). Below is an example of what the string can look like: { ‘title’: ‘ComputingandInformationsystems’, ‘id’: 1, ‘children’: ‘true’, ‘groups’: [{ ‘title’: ‘LeveloneCIS’, ‘id’: 2, ‘children’: ‘true’, ‘groups’: [{ … Read more

GSON throwing “Expected BEGIN_OBJECT but was BEGIN_ARRAY”?

I’m trying to parse a JSON string like this one [ { “updated_at”:”2012-03-02 21:06:01″, “fetched_at”:”2012-03-02 21:28:37.728840″, “description”:null, “language”:null, “title”:”JOHN”, “url”:”http://rus.JOHN.JOHN/rss.php”, “icon_url”:null, “logo_url”:null, “id”:”4f4791da203d0c2d76000035″, “modified”:”2012-03-02 23:28:58.840076″ }, { “updated_at”:”2012-03-02 14:07:44″, “fetched_at”:”2012-03-02 21:28:37.033108″, “description”:null, “language”:null, “title”:”PETER”, “url”:”http://PETER.PETER.lv/rss.php”, “icon_url”:null, “logo_url”:null, “id”:”4f476f61203d0c2d89000253″, “modified”:”2012-03-02 23:28:57.928001″ } ] into a list of objects. List<ChannelSearchEnum> lcs = (List<ChannelSearchEnum>) new Gson().fromJson( jstring , … Read more

Gson: How to exclude specific fields from Serialization without annotations

I’m trying to learn Gson and I’m struggling with field exclusion. Here are my classes public class Student { private Long id; private String firstName = “Philip”; private String middleName = “J.”; private String initials = “P.F”; private String lastName = “Fry”; private Country country; private Country countryOfBirth; } public class Country { private Long … Read more

Deserialize a List object with Gson?

I want to transfer a list object via Google Gson, but I don’t know how to deserialize generic types. What I tried after looking at this (BalusC’s answer): MyClass mc = new Gson().fromJson(result, new List<MyClass>() {}.getClass()); but then I get an error in Eclipse saying “The type new List<MyClass>() {} must implement the inherited abstract … Read more