I am new to Android development. I have a node test server running that returns the following json post response
res.json({ userName: 'test@gmail.com', ratedOn: new Date(), rating: Math.ceil(Math.random() * 5) });
I am using gson to parse the response into an object Class Definition of the target class
public class RateWork {
public int rating;
public Date ratedOn;
public String userName;
public RateWork(int rating, Date ratedOn, String userName){
this.rating = rating;
this.ratedOn = ratedOn;
this.userName = userName;
}
}
In the client(Android side) i am using volley to capture the response.
StringRequest jsonObjReq = new StringRequest(Request.Method.POST, Constants.API_POST_RATING,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("TEST", response);
RateWork rw = gson.fromJson(response, RateWork.class);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("TEST", "Error: " + error.getMessage());
}
}
Log of the response
D/TEST: {"userName":"test@gmail.com","ratedOn":"Sat Dec 09 14:10:49 GMT+05:30 2017","rating":3}
I get an exception at this line -> com.google.gson.JsonSyntaxException
RateWork rw = gson.fromJson(response, RateWork.class);
Please help fix the error.