com.google.gson.JsonSyntaxException: 2018-04-19 21: 42: 21
в то время как приложение извлекает метку времени в виде строки, используя gson.fromJson (ответ, пользователь []. класс)
@Entity
public class User {
@TypeConverters({JConverter.class})
private Date date_added;
public Date getDate_added() {
return date_added;
}
public void setDate_added(Date date_added) {
this.date_added = date_added;
}
и мой класс JConverter
public class Converters {
@TypeConverter
public static Date fromTimestamp(Long value) {
return value == null ? null : new Date(value);`enter code here`
}
@TypeConverter
public static Long dateToTimestamp(Date date) {
return date == null ? null : date.getTime();
}
}
MainActivity.java
StringRequest getTable = new StringRequest(Request.Method.POST, URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("tagg", response); //response is correct
Gson gson = new Gson();
users = gson.fromJson(response,User[].class);//exception occurs here
userDatabase.userDao().fillUsers(users);
.....
JSON-ответ
[{"name":"jayesh","date_added":"2018-04-19 21:42:21"},{"name":"marathe","date_added":"2018-04-19 22:37:17"},{"name":"sagar","date_added":"2018-04-19 22:37:50"},{"name":"omkar","date_added":"2018-04-19 22:37:58"},{"name":"vedant","date_added":"2018-04-19 22:38:04"},{"name":"kalpesh","date_added":"2018-04-19 22:38:14"},{"name":"ashay","date_added":"2018-04-19 22:38:21"},{"name":"ameya","date_added":"2018-04-19 22:38:28"},{"name":"abhishek","date_added":"2018-04-19 22:38:34"}]
ИСКЛЮЧЕНИЕ
--------- начало аварии
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.dell.testingapplication, PID: 4297
com.google.gson.JsonSyntaxException: 2018-04-19 21:42:21
at com.google.gson.internal.bind.DateTypeAdapter.deserializeToDate(DateTypeAdapter.java:81)
at com.google.gson.internal.bind.DateTypeAdapter.read(DateTypeAdapter.java:66)
at com.google.gson.internal.bind.DateTypeAdapter.read(DateTypeAdapter.java:41)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:117)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:217)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
at com.google.gson.internal.bind.ArrayTypeAdapter.read(ArrayTypeAdapter.java:72)
at com.google.gson.Gson.fromJson(Gson.java:814)
at com.google.gson.Gson.fromJson(Gson.java:779)
at com.google.gson.Gson.fromJson(Gson.java:728)
at com.google.gson.Gson.fromJson(Gson.java:700)
at com.example.dell.testingapplication.MainActivity$1.onResponse(MainActivity.java:44)
at com.example.dell.testingapplication.MainActivity$1.onResponse(MainActivity.java:38)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:78)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:106)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.text.ParseException: Unparseable date: "2018-04-19 21:42:21"
at java.text.DateFormat.parse(DateFormat.java:358)
at com.google.gson.internal.bind.DateTypeAdapter.deserializeToDate(DateTypeAdapter.java:79)
at com.google.gson.internal.bind.DateTypeAdapter.read(DateTypeAdapter.java:66)
at com.google.gson.internal.bind.DateTypeAdapter.read(DateTypeAdapter.java:41)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:117)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:217)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
at com.google.gson.internal.bind.ArrayTypeAdapter.read(ArrayTypeAdapter.java:72)
at com.google.gson.Gson.fromJson(Gson.java:814)
at com.google.gson.Gson.fromJson(Gson.java:779)
at com.google.gson.Gson.fromJson(Gson.java:728)
at com.google.gson.Gson.fromJson(Gson.java:700)
at com.example.dell.testingapplication.MainActivity$1.onResponse(MainActivity.java:44)
at com.example.dell.testingapplication.MainActivity$1.onResponse(MainActivity.java:38)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:78)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:106)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)