Skip to content

Commit 38e759e

Browse files
committed
Implement Serializable in JSONObject and JSONArray
1 parent 26f4848 commit 38e759e

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/main/java/org/json/JSONArray.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ of this software and associated documentation files (the "Software"), to deal
2525
*/
2626

2727
import java.io.IOException;
28+
import java.io.Serializable;
2829
import java.io.StringWriter;
2930
import java.io.Writer;
3031
import java.lang.reflect.Array;
@@ -81,7 +82,14 @@ of this software and associated documentation files (the "Software"), to deal
8182
* @author JSON.org
8283
* @version 2016-08/15
8384
*/
84-
public class JSONArray implements Iterable<Object> {
85+
public class JSONArray implements Iterable<Object>, Serializable {
86+
87+
/**
88+
* Serialization version ID. This should only be changed under certain
89+
* circumstances, see <a href="https://docs.oracle.com/javase/8/docs/
90+
* platform/serialization/spec/version.html#6678">JDK documentation details</a>
91+
*/
92+
private static final long serialVersionUID = -3758785237786450861L;
8593

8694
/**
8795
* The arrayList where the JSONArray's properties are kept.

src/main/java/org/json/JSONObject.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.json;
22

3-
import java.io.Closeable;
3+
import java.io.*;
44

55
/*
66
Copyright (c) 2002 JSON.org
@@ -26,9 +26,6 @@ of this software and associated documentation files (the "Software"), to deal
2626
SOFTWARE.
2727
*/
2828

29-
import java.io.IOException;
30-
import java.io.StringWriter;
31-
import java.io.Writer;
3229
import java.lang.annotation.Annotation;
3330
import java.lang.reflect.Field;
3431
import java.lang.reflect.InvocationTargetException;
@@ -100,7 +97,7 @@ of this software and associated documentation files (the "Software"), to deal
10097
* @author JSON.org
10198
* @version 2016-08-15
10299
*/
103-
public class JSONObject {
100+
public class JSONObject implements Serializable {
104101
/**
105102
* JSONObject.NULL is equivalent to the value that JavaScript calls null,
106103
* whilst Java's null is equivalent to the value that JavaScript calls
@@ -151,7 +148,15 @@ public String toString() {
151148
return "null";
152149
}
153150
}
154-
151+
152+
/**
153+
* Serialization version ID. This should only be changed under certain
154+
* circumstances, see <a href="https://docs.oracle.com/javase/8/docs/
155+
* platform/serialization/spec/version.html#6678">JDK documentation details</a>
156+
*/
157+
private static final long serialVersionUID = 5240016072008648204L;
158+
159+
155160
/**
156161
* Regular Expression Pattern that matches JSON Numbers. This is primarily used for
157162
* output to guarantee that we are always writing valid JSON.

0 commit comments

Comments
 (0)