Permalink
Browse files

Fix well formed exception (#1105)

The previous exception was styled in the following way:
... ["DATE']...
This commit will fix the different quote marks and replace the " with '
  • Loading branch information...
StefMa authored and inder123 committed Jun 23, 2017
1 parent 74e3711 commit 1c09b3f92899b2a88a216932a72a0708e4a40550
@@ -229,7 +229,7 @@ private static Date parse(String date, ParsePosition pos) throws ParseException
} catch (IllegalArgumentException e) {
fail = e;
}
String input = (date == null) ? null : ('"' + date + "'");
String input = (date == null) ? null : ("'" + date + "'");
throw new ParseException("Failed to parse date [" + input + "]: " + fail.getMessage(), pos.getIndex());
}
@@ -22,7 +22,6 @@
import com.google.gson.GsonBuilder;
import junit.framework.TestCase;
import org.junit.Assert;
import java.util.Arrays;
import java.util.List;
@@ -50,10 +49,10 @@ public void testList() {
// Throws NullPointerException without the fix in https://github.com/google/gson/pull/1103
String json = gson.toJson(sandwiches);
Assert.assertEquals("{\"sandwiches\":[{\"bread\":\"white\",\"cheese\":\"cheddar\"},{\"bread\":\"whole wheat\",\"cheese\":\"swiss\"}]}", json);
assertEquals("{\"sandwiches\":[{\"bread\":\"white\",\"cheese\":\"cheddar\"},{\"bread\":\"whole wheat\",\"cheese\":\"swiss\"}]}", json);
MultipleSandwiches sandwichesFromJson = gson.fromJson(json, MultipleSandwiches.class);
Assert.assertEquals(sandwiches, sandwichesFromJson);
assertEquals(sandwiches, sandwichesFromJson);
}
static class Sandwich {
@@ -22,6 +22,7 @@
import java.util.Locale;
import java.util.TimeZone;
import com.google.gson.JsonParseException;
import junit.framework.TestCase;
import com.google.gson.Gson;
@@ -76,4 +77,13 @@ public void testNullDateSerialization() {
String json = gson.toJson(null, Date.class);
assertEquals("null", json);
}
public void testWellFormedParseException() {
try {
gson.fromJson("2017-06-20T14:32:30", Date.class);
fail("No exception");
} catch (JsonParseException exe) {
assertEquals(exe.getMessage(), "java.text.ParseException: Failed to parse date ['2017-06-20T14']: 2017-06-20T14");
}
}
}

0 comments on commit 1c09b3f

Please sign in to comment.