Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid time zone indicator ' ' #1297

Closed
libsgh opened this issue Apr 23, 2018 · 7 comments
Closed

Invalid time zone indicator ' ' #1297

libsgh opened this issue Apr 23, 2018 · 7 comments

Comments

@libsgh
Copy link

libsgh commented Apr 23, 2018

This my Gson code:

protected Object fromJson(String json, Type t) {
try {
			Gson g = new Gson();
			Object o = g.fromJson(json, t);
			return o;
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return null;
  }
}

I have an object which have a 2 Timestamp fields and I want to consume a json response using Gson but I have got an Invalid time zone indicator ' '.But this is not always happening. I don't know why.
So this is out put :

Caused by: java.text.ParseException: Failed to parse date ["2018-04-12 18:38:02']: Invalid time zone indicator ' '
	at com.google.gson.internal.bind.util.ISO8601Utils.parse(ISO8601Utils.java:274) ~[gson-2.8.2.jar!/:?]
	at com.google.gson.internal.bind.DateTypeAdapter.deserializeToDate(DateTypeAdapter.java:72) ~[gson-2.8.2.jar!/:?]
	... 106 more
Caused by: java.lang.IndexOutOfBoundsException: Invalid time zone indicator ' '
	at com.google.gson.internal.bind.util.ISO8601Utils.parse(ISO8601Utils.java:245) ~[gson-2.8.2.jar!/:?]
	at com.google.gson.internal.bind.DateTypeAdapter.deserializeToDate(DateTypeAdapter.java:72) ~[gson-2.8.2.jar!/:?]
	... 106 more

This my Gson data:

[
    {
        "id": 2267,
        "code": "2100130106335294543080001",
        "name": "ly123",
        "servicetype": "VOD",
        "showname": "ly123",
        "type1": 1,
        "pictureurl1": "",
        "pictureurl2": "",
        "status": 1,
        "isdelete": false,
        "checkstatus1": 10,
        "createtime": "2018-04-12 18:38:02",
        "updatetime": "2018-04-12 18:38:15",
        "description": "",
        "sgs": [],
        "sgCodes": [],
        "isPool": false
    }
]
@7788jay
Copy link

7788jay commented May 23, 2018

我也碰到了

@fradrick
Copy link

Same issue here, did you get a solution?

@reki-cool
Copy link

同问,求解决办法呢

@7788jay
Copy link

7788jay commented Jun 29, 2018

@duyanhan1995 需要设置时间格式才能用,默认的不是标准格式。 new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss")

@7788jay
Copy link

7788jay commented Jun 29, 2018

@fradrick Need to set the time format to use, the default is not the standard format. new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss")

@reki-cool
Copy link

@7788jay 多谢!问题已经解决

@libsgh libsgh closed this as completed Jul 2, 2018
@Jigsawk
Copy link

Jigsawk commented Mar 4, 2019

@7788jay 我哭辽

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants