-
Notifications
You must be signed in to change notification settings - Fork 49
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
VA-1963 wrapping date deserialization #148
Conversation
…he client can decide if it wants to crash or not
…at way there can be no misconfiguration
I will look at this later today |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such a simple solve to a ridiculous bug. Great find.
Did you happen to file a bug with Gson? I think that might help some other people facing this issue.
@@ -125,7 +125,7 @@ private String toPrettyFormat(String jsonString) { | |||
JsonParser parser = new JsonParser(); | |||
JsonObject json = parser.parse(jsonString).getAsJsonObject(); | |||
|
|||
Gson gson = new GsonBuilder().setPrettyPrinting().create(); | |||
Gson gson = VimeoNetworkUtil.getGsonBuilder().setPrettyPrinting().create(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
* using the {@link ISO8601Utils} class that catches errors | ||
* and reports them to the client application, allowing | ||
* them to decide if they should crash or not. If we just | ||
* rely on the default adapter used by JSON, we are unable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this say Gson?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
* and reports them to the client application, allowing | ||
* them to decide if they should crash or not. If we just | ||
* rely on the default adapter used by JSON, we are unable | ||
* to absorb date parsing errors or log them correctly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it wasn't just logging them incorrectly.....it was serializing it incorrectly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I'll update these docs to reflect the new findings
Gson bug filed here google/gson#935 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I am finished with the review. Godspeed.
try { | ||
return json == null ? null : ISO8601Utils.parse(json.getAsString(), new ParsePosition(0)); | ||
} catch (ParseException e) { | ||
ClientLogger.e("Incorrectly formatted date sent from server: " + json.getAsString(), e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above, but maybe be a little more careful with getAsString?
@@ -125,7 +125,7 @@ private String toPrettyFormat(String jsonString) { | |||
JsonParser parser = new JsonParser(); | |||
JsonObject json = parser.parse(jsonString).getAsJsonObject(); | |||
|
|||
Gson gson = new GsonBuilder().setPrettyPrinting().create(); | |||
Gson gson = VimeoNetworkUtil.getGsonBuilder().setPrettyPrinting().create(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it would help to actually log the exception in the log below? Does it have any useful info?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just log it then, it couldn't hurt. It is just one parameter...
return new JsonDeserializer<Date>() { | ||
@Override | ||
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) | ||
throws JsonParseException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't actually throw a JsonParseException, so maybe ditch the the "throws"? It'll still be a legit overrride.
Also, if you just look at the javadocs for getAsString there are other types of exceptions that can occur here due to getAsString. Maybe we should swallow more than just ParseException? But perhaps more importantly, unless I am missing something...
Here's the weird thing regarding getAsString, in the version of gson that I have, this method always throws an UnsupportedOperationException. I'm confused...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding unsupported operation exception, it's because JsonElement is an abstract class, so the implementation is hidden
Ticket
VA-1963
Ticket Summary
The date deserialization is crashing sometimes because somehow dates are being serialized incorrectly.
Implementation Summary
How to Test
make sure dates still show up correctly