Skip to content

Commit e3292f5

Browse files
committed
Add more testing for JDK serializability of exceptions
1 parent d652a84 commit e3292f5

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

release-notes/VERSION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ JSON library.
1818

1919
#209: Make use of `_allowMultipleMatches` in `FilteringParserDelegate`
2020
(contributed by Lokesh N)
21-
- Make `processor` transient in `JsonParseException` to keep it Serializable
21+
- Make `processor` transient in `JsonParseException`, `JsonGenerationException`
22+
to keep both Serializable
2223

2324
2.7.3 (16-Mar-2016)
2425

src/main/java/com/fasterxml/jackson/core/JsonGenerationException.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public class JsonGenerationException
1515
{
1616
private final static long serialVersionUID = 123; // Stupid eclipse...
1717

18-
protected JsonGenerator _processor;
18+
// transient since 2.7.4
19+
protected transient JsonGenerator _processor;
1920

2021
@Deprecated // since 2.7
2122
public JsonGenerationException(Throwable rootCause) {

src/test/java/com/fasterxml/jackson/core/TestJDKSerializability.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,58 @@ public void testPrettyPrinter() throws Exception
4747
// what should we test?
4848
assertNotNull(back);
4949
}
50+
51+
public void testLocation() throws Exception
52+
{
53+
JsonFactory jf = new JsonFactory();
54+
JsonParser jp = jf.createParser(" { }");
55+
assertToken(JsonToken.START_OBJECT, jp.nextToken());
56+
JsonLocation loc = jp.getCurrentLocation();
57+
58+
byte[] stuff = jdkSerialize(loc);
59+
JsonLocation loc2 = jdkDeserialize(stuff);
60+
assertNotNull(loc2);
61+
62+
assertEquals(loc.getLineNr(), loc2.getLineNr());
63+
assertEquals(loc.getColumnNr(), loc2.getColumnNr());
64+
jp.close();
65+
}
66+
67+
public void testParseException() throws Exception
68+
{
69+
JsonFactory jf = new JsonFactory();
70+
JsonParser p = jf.createParser(" { garbage! }");
71+
JsonParseException exc = null;
72+
try {
73+
p.nextToken();
74+
p.nextToken();
75+
fail("Should not get here");
76+
} catch (JsonParseException e) {
77+
exc = e;
78+
}
79+
p.close();
80+
byte[] stuff = jdkSerialize(exc);
81+
JsonParseException result = jdkDeserialize(stuff);
82+
assertNotNull(result);
83+
}
84+
85+
public void testGenerationException() throws Exception
86+
{
87+
JsonFactory jf = new JsonFactory();
88+
JsonGenerator g = jf.createGenerator(new ByteArrayOutputStream());
89+
JsonGenerationException exc = null;
90+
g.writeStartObject();
91+
try {
92+
g.writeNumber(4);
93+
fail("Should not get here");
94+
} catch (JsonGenerationException e) {
95+
exc = e;
96+
}
97+
g.close();
98+
byte[] stuff = jdkSerialize(exc);
99+
JsonGenerationException result = jdkDeserialize(stuff);
100+
assertNotNull(result);
101+
}
50102

51103
/*
52104
/**********************************************************

0 commit comments

Comments
 (0)