JSON requires string values to be quoted (including the keywords). And the name/value separator for JSON is a colon, not equals.
So to be valid JSON the text should be:
{"expDate":"4/6/2014", "iconPath":"/data/.../5000112558265", "id":5000112558265, "name":"Coca-Cola Zéro"}
Refer to http://json.org for full details.
I just noticed that your toString
implementation uses GSON to produce ostensibly JSON output, but either that toString
method is not being used, or GSON has a very mistaken understanding of what constitutes valid JSON. My expectation is that it's surely the former.
I now see the problem, I think, now that I look closer; whatever they are your deserialized objects are not instances of Product
. So the following code:
for(final Object product : deserializedProducts) {
//System.out.println(product.toString());
result.add(gson.fromJson(product.toString(), Product.class));
does not invoke Product.toString
, but the toString
of whatever object gson.fromJson(serializedProducts, List.class);
produces and adds to the list.
You should add product.getClass()
to your debug output to prove this. And then you should should investigate how to get actual instances of Product
created.