-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make Object and JsonElement deserialization iterative Often when Object and JsonElement are deserialized the format of the JSON data is unknown and it might come from an untrusted source. To avoid a StackOverflowError from maliciously crafted JSON, deserialize Object and JsonElement iteratively instead of recursively. Concept based on FasterXML/jackson-databind@51fd2fa But implementation is not based on it. * Improve imports grouping * Address review feedback
- Loading branch information
1 parent
d2aee65
commit 2d01d6a
Showing
6 changed files
with
370 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
gson/src/test/java/com/google/gson/JsonParserParameterizedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.google.gson; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.junit.runners.Parameterized.Parameter; | ||
import org.junit.runners.Parameterized.Parameters; | ||
|
||
@RunWith(Parameterized.class) | ||
public class JsonParserParameterizedTest { | ||
@Parameters | ||
public static Iterable<String> data() { | ||
return Arrays.asList( | ||
"[]", | ||
"{}", | ||
"null", | ||
"1.0", | ||
"true", | ||
"\"string\"", | ||
"[true,1.0,null,{},2.0,{\"a\":[false]},[3.0,\"test\"],4.0]", | ||
"{\"\":1.0,\"a\":true,\"b\":null,\"c\":[],\"d\":{\"a1\":2.0,\"b2\":[true,{\"a3\":3.0}]},\"e\":[{\"f\":4.0},\"test\"]}" | ||
); | ||
} | ||
|
||
private final TypeAdapter<JsonElement> adapter = new Gson().getAdapter(JsonElement.class); | ||
@Parameter | ||
public String json; | ||
|
||
@Test | ||
public void testParse() throws IOException { | ||
JsonElement deserialized = JsonParser.parseString(json); | ||
String actualSerialized = adapter.toJson(deserialized); | ||
|
||
// Serialized JsonElement should be the same as original JSON | ||
assertEquals(json, actualSerialized); | ||
} | ||
} |
Oops, something went wrong.