I created an android applicatopn with a rest api. In here I used gson
for the rest api and used retrofit
to connect this rest api and android application.
In my application, I tried to get some data from the rest api by using an id. Then I got the following error log.(I didn't post my applicqation name with this error log).
Should I change some properties in rest api ? or any changes to application. Currently I test my android application with rest api on localhost.
What should I do to handle this exception ?
This is my error log,
com.google.gson.JsonSyntaxException: 1989-10-11
at com.google.gson.DefaultDateTypeAdapter.deserializeToDate(DefaultDateTypeAdapter.java:107)
at com.google.gson.DefaultDateTypeAdapter.deserialize(DefaultDateTypeAdapter.java:82)
at com.google.gson.DefaultDateTypeAdapter.deserialize(DefaultDateTypeAdapter.java:35)
at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:103)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:196)
at com.google.gson.Gson.fromJson(Gson.java:810)
at com.google.gson.Gson.fromJson(Gson.java:775)
at retrofit.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:36)
at retrofit.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:24)
at retrofit.OkHttpCall.parseResponse(OkHttpCall.java:148)
at retrofit.OkHttpCall.access$100(OkHttpCall.java:29)
at retrofit.OkHttpCall$1.onResponse(OkHttpCall.java:94)
at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:168)
at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.text.ParseException: Unparseable date: "1989-10-11" (at offset 10)
at java.text.DateFormat.parse(DateFormat.java:555)
at com.google.gson.DefaultDateTypeAdapter.deserializeToDate(DefaultDateTypeAdapter.java:105)
... 17 more
Update
I found following code line in my retrofit call, I think this is the reason for the exception,
Gson gson = new GsonBuilder()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss")
.create();
But I have no idea about convert this date format for common date format.
Currently I have no idea how to handle this exception . Have any ideas ?