mirror of
https://github.com/stleary/JSON-java.git
synced 2026-04-04 00:00:53 -04:00
Ignore static fields in JSONObject.fromJson()
This commit is contained in:
@@ -66,6 +66,7 @@ import org.json.junit.data.CustomClassF;
|
||||
import org.json.junit.data.CustomClassG;
|
||||
import org.json.junit.data.CustomClassH;
|
||||
import org.json.junit.data.CustomClassI;
|
||||
import org.json.junit.data.CustomClassJ;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.After;
|
||||
import org.junit.Ignore;
|
||||
@@ -4232,4 +4233,21 @@ public class JSONObjectTest {
|
||||
CustomClassI compareClassI = new CustomClassI(dataList);
|
||||
assertEquals(customClassI.integerMap.toString(), compareClassI.integerMap.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jsonObjectParseFromJson_9() {
|
||||
JSONObject object = new JSONObject();
|
||||
object.put("number", 12);
|
||||
object.put("classState", "mutated");
|
||||
|
||||
String initialClassState = CustomClassJ.classState;
|
||||
CustomClassJ.classState = "original";
|
||||
try {
|
||||
CustomClassJ customClassJ = object.fromJson(CustomClassJ.class);
|
||||
assertEquals(12, customClassJ.number);
|
||||
assertEquals("original", CustomClassJ.classState);
|
||||
} finally {
|
||||
CustomClassJ.classState = initialClassState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
8
src/test/java/org/json/junit/data/CustomClassJ.java
Normal file
8
src/test/java/org/json/junit/data/CustomClassJ.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package org.json.junit.data;
|
||||
|
||||
public class CustomClassJ {
|
||||
public static String classState = "original";
|
||||
public int number;
|
||||
|
||||
public CustomClassJ() {}
|
||||
}
|
||||
Reference in New Issue
Block a user