Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1c09b3f

Browse files
StefMainder123
authored andcommittedJun 23, 2017
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 '
1 parent 74e3711 commit 1c09b3f

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed
 

‎extras/src/main/java/com/google/gson/typeadapters/UtcDateTypeAdapter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private static Date parse(String date, ParsePosition pos) throws ParseException
229229
} catch (IllegalArgumentException e) {
230230
fail = e;
231231
}
232-
String input = (date == null) ? null : ('"' + date + "'");
232+
String input = (date == null) ? null : ("'" + date + "'");
233233
throw new ParseException("Failed to parse date [" + input + "]: " + fail.getMessage(), pos.getIndex());
234234
}
235235

‎extras/src/test/java/com/google/gson/typeadapters/PostConstructAdapterFactoryTest.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.google.gson.GsonBuilder;
2323

2424
import junit.framework.TestCase;
25-
import org.junit.Assert;
2625

2726
import java.util.Arrays;
2827
import java.util.List;
@@ -50,10 +49,10 @@ public void testList() {
5049

5150
// Throws NullPointerException without the fix in https://github.com/google/gson/pull/1103
5251
String json = gson.toJson(sandwiches);
53-
Assert.assertEquals("{\"sandwiches\":[{\"bread\":\"white\",\"cheese\":\"cheddar\"},{\"bread\":\"whole wheat\",\"cheese\":\"swiss\"}]}", json);
52+
assertEquals("{\"sandwiches\":[{\"bread\":\"white\",\"cheese\":\"cheddar\"},{\"bread\":\"whole wheat\",\"cheese\":\"swiss\"}]}", json);
5453

5554
MultipleSandwiches sandwichesFromJson = gson.fromJson(json, MultipleSandwiches.class);
56-
Assert.assertEquals(sandwiches, sandwichesFromJson);
55+
assertEquals(sandwiches, sandwichesFromJson);
5756
}
5857

5958
static class Sandwich {

‎extras/src/test/java/com/google/gson/typeadapters/UtcDateTypeAdapterTest.java

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Locale;
2323
import java.util.TimeZone;
2424

25+
import com.google.gson.JsonParseException;
2526
import junit.framework.TestCase;
2627

2728
import com.google.gson.Gson;
@@ -76,4 +77,13 @@ public void testNullDateSerialization() {
7677
String json = gson.toJson(null, Date.class);
7778
assertEquals("null", json);
7879
}
80+
81+
public void testWellFormedParseException() {
82+
try {
83+
gson.fromJson("2017-06-20T14:32:30", Date.class);
84+
fail("No exception");
85+
} catch (JsonParseException exe) {
86+
assertEquals(exe.getMessage(), "java.text.ParseException: Failed to parse date ['2017-06-20T14']: 2017-06-20T14");
87+
}
88+
}
7989
}

0 commit comments

Comments
 (0)