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

VA-1963 wrapping date deserialization #148

Merged
merged 3 commits into from
Sep 27, 2016
Merged

Conversation

anthonycr
Copy link
Contributor

@anthonycr anthonycr commented Sep 26, 2016

Ticket

VA-1963

Ticket Summary

The date deserialization is crashing sometimes because somehow dates are being serialized incorrectly.

Implementation Summary

  • Switch to using ISO8601Utils directly rather than relying on the default type adapter provided by Gson.
  • Wrap the deserialization in a try catch so we can choose whether or not to crash on the client side if there is a problem.

How to Test

make sure dates still show up correctly

@howardrigberg
Copy link
Contributor

I will look at this later today

Copy link
Contributor

@kvenn kvenn left a 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();
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this say Gson?

Copy link
Contributor Author

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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

@anthonycr
Copy link
Contributor Author

Gson bug filed here google/gson#935

@anthonycr anthonycr merged commit aaa4595 into v2.0.0 Sep 27, 2016
@anthonycr anthonycr deleted the VA-1963-date-parsing branch September 27, 2016 17:12
Copy link
Contributor

@howardrigberg howardrigberg left a 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);
Copy link
Contributor

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();
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know

Copy link
Contributor

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 {
Copy link
Contributor

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...

Copy link
Contributor Author

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

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

Successfully merging this pull request may close these issues.

3 participants