Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
0afd266
JSONObject and JSONArray initialization:
Oct 4, 2015
409eb9f
changed all method signatures containing collections and maps to accept
Oct 11, 2015
25b5aa7
changed Map<String, ?> method parameters to Map<?,?>
Oct 11, 2015
4e77383
Properly overrides the Exception class.
Oct 12, 2015
ceba8e8
Fixes possible NPE
Oct 12, 2015
e239e19
Allows a custom message to be passed with a cause.
Oct 12, 2015
0e13241
Expands javadoc
Oct 12, 2015
1b06a80
makes params final
Oct 12, 2015
5ddc515
removed 6 unnecessary @SuppressWarnings("unchecked") annotations.
Oct 12, 2015
1448163
fixes file date
johnjaylward Oct 14, 2015
637c1fe
updates file dates
johnjaylward Oct 14, 2015
09b6af4
Merge pull request #160 from johnjaylward/FixXMLNPE
stleary Oct 18, 2015
6757e04
Fix NullPointerException in XML.toString(object, tagName)
stleary Oct 18, 2015
b0a9507
Merge pull request #159 from johnjaylward/FixExceptionInheritance
stleary Oct 18, 2015
e7f4eb5
Set version date to match commit date, convert tabs to spaces.
stleary Oct 18, 2015
a07d391
Include latest Maven release information
stleary Oct 25, 2015
91c6f09
Modifies XML output to be handled the same for a native java array as…
Oct 26, 2015
7886c96
Changes JSONArray for loops to use the new iterators.
Oct 26, 2015
105426b
Formatting
Oct 26, 2015
dfd1911
Merge pull request #168 from douglascrockford/readme-maven-info
stleary Oct 29, 2015
564ad2c
Merge pull request #153 from treyerl/master
stleary Oct 29, 2015
33ae025
Update JSONObject.java
stleary Oct 29, 2015
a109f58
Update JSONArray.java
stleary Oct 29, 2015
5f2e77f
Update readme with proposed release information
stleary Nov 21, 2015
44275e3
Merge pull request #175 from douglascrockford/release-20151123
stleary Nov 24, 2015
cadba94
Update JavaDoc for JSONObject Constructors
andrew-fletcher Dec 2, 2015
2ec538f
Merge pull request #179 from andrew-fletcher/UpdateJavaDocForJSONOBject
stleary Dec 6, 2015
39e3ccc
Update version
stleary Dec 6, 2015
ec8f649
Merge branch 'master' of https://github.com/douglascrockford/JSON-java
Dec 8, 2015
23cf659
Remove executable permission bit from file mode
netheril96 Dec 9, 2015
03dd662
Merge pull request #180 from netheril96/my
stleary Dec 9, 2015
4830259
Merge branch 'master' of https://github.com/douglascrockford/JSON-java
Dec 9, 2015
8688494
change to public, write(writer, indentfactor, indent)
stleary Dec 24, 2015
e6f5047
Merge pull request #185 from douglascrockford/write-with-indent-params
stleary Dec 30, 2015
757fd56
Merge pull request #170 from johnjaylward/HandleArraysConsistently
stleary Jan 1, 2016
a971736
Update version string for https://github.com/douglascrockford/JSON-ja…
stleary Jan 1, 2016
e2a0bb1
Update README with number information
stleary Jan 1, 2016
2b2fac3
Broke up some overly long lines.
stleary Jan 1, 2016
9950350
Merge pull request #186 from douglascrockford/update-readme-with-numb…
stleary Jan 3, 2016
5b67330
Merge branch 'master' of https://github.com/douglascrockford/JSON-java
Jan 27, 2016
07b2d65
Fixes #187 -0 now returns as a double.
Jan 27, 2016
39b1c0c
fixes error in -0 check
Jan 27, 2016
3007fc8
Removes custom XML stringToValue method in favor of keeping a consistent
Jan 27, 2016
c2b3f2b
adds back in the XML.stringToValue method, but deprecates it.
Jan 27, 2016
97f1b27
Merge pull request #188 from johnjaylward/FixNegativeZero
stleary Jan 30, 2016
62486fd
Version date
stleary Jan 30, 2016
93c79ca
Version date
stleary Jan 30, 2016
ba2585f
Version date
stleary Jan 30, 2016
60349ec
Java 1.6 compatibility.
skreutzer Feb 9, 2016
07a0f60
Merge pull request #195 from publishing-systems/master
stleary Feb 13, 2016
2657915
Update README
stleary Feb 14, 2016
f024b52
Adds JSONArray toList method and JSONObject toMap method
joeferner Feb 27, 2016
26477f4
Merge pull request #203 from joeferner/to-java
stleary Mar 5, 2016
2f3af56
Update date of merge.
stleary Mar 5, 2016
25a8797
Update date of merge.
stleary Mar 5, 2016
86cbfbc
Added CSV change to CDL.java
brianrussell2 Apr 12, 2016
612e419
initial implementation of JSONPointer
erosb Apr 17, 2016
5bee7e3
escape handling improvements & URL fragment notation handling
erosb Apr 26, 2016
792c6f6
improved failure handling
erosb Apr 26, 2016
45bd72c
added JSONObject#query() and JSONPointer#query() methods
erosb Apr 26, 2016
5223aad
added some javadoc to JSONPointer
erosb Apr 26, 2016
bff3527
removed @author tag from JSONPointerException
erosb Apr 26, 2016
c1a789a
adding missing license headers
erosb Apr 26, 2016
cbb1546
README improvements for stleary/JSON-Java#218
erosb Apr 28, 2016
1ca8933
fix to compile with 1.6.0_45
stleary Apr 29, 2016
f239dc7
Merge pull request #219 from captainIowa/master
stleary May 2, 2016
ebf08f5
Merge pull request #226 from stleary/restore-1.6-compatibility
stleary May 2, 2016
cad2342
Update JSONObject.java
stleary May 3, 2016
f21ffbe
Update CDL.java
stleary May 3, 2016
d833c2d
added builder class for JSONPointer, and implemented toString() and t…
erosb May 3, 2016
5ae6a66
added javadoc & null check in Builder#append(String)
erosb May 3, 2016
c044eb1
added copying to JSONPointer constructor
erosb May 5, 2016
8a72509
Merge pull request #222 from erosb/master
stleary May 14, 2016
4a458a9
add timestamps to recent commits, javadocs for JSONObject, JSONArray …
stleary May 14, 2016
9a81b40
added some JavaDocs
stleary May 14, 2016
56be31e
fixing stleary/JSON-Java#233
erosb May 16, 2016
b2bde1f
Merge pull request #234 from erosb/master
stleary May 21, 2016
8083208
Update JSONArray.java
stleary May 21, 2016
612dafc
Update JSONObject.java
stleary May 21, 2016
dfa651e
Make nextString throw a JSONException instead of a NumberFormatExcept…
madsager Jun 2, 2016
16a86d7
Pass in the throwable that caused the error.
madsager Jun 2, 2016
eb569b5
Merge pull request #236 from madsager/master
stleary Jun 8, 2016
b3abaa5
Merge pull request #1 from stleary/master
johnjaylward Jun 16, 2016
42791ab
Updates README to note that the parser does allow some invalid JSON
Jun 16, 2016
86e8f7b
Update README
johnjaylward Jun 17, 2016
a8a7189
Create LICENSE
johnjaylward Jun 22, 2016
239e0b7
Merge pull request #242 from johnjaylward/issue240
stleary Jul 2, 2016
04181fb
Merge pull request #246 from johnjaylward/LicenseFile
stleary Jul 2, 2016
7627d40
reduces the use of unnecessary exceptions
xxxertetet Jul 8, 2016
42e0944
Brings in changes from PR #70 to be updated to HEAD
yaccob Nov 14, 2012
9370437
Updates to the Javadoc for exceptions
Jul 18, 2016
09d37e5
Cleans up the JSONML changes and adds similar changes to the XML class
Jul 18, 2016
abf2963
Revert "reduces the use of unnecessary exceptions"
Jul 19, 2016
3890bfa
reduce the use of unnecessary exceptions
Jul 19, 2016
2c228ec
Merge pull request #249 from Simulant87/master
stleary Jul 27, 2016
3080b8b
Merge pull request #253 from johnjaylward/OptionalTypeConversion
stleary Aug 1, 2016
8e07959
Update README
stleary Aug 7, 2016
0c157ca
JSONWriter uses Appendable.
run2000 Aug 8, 2016
45a7dec
Revert "reduces the use of unnecessary exceptions"
stleary Aug 9, 2016
154cfda
Merge pull request #261 from stleary/revert-249-master
stleary Aug 10, 2016
37582a4
Update README
stleary Aug 10, 2016
f881b61
Update XML.java
stleary Aug 10, 2016
4e8e24d
Merge pull request #259 from run2000/appendable_v2
stleary Aug 11, 2016
91107e3
Adds support to JSONObject wrap and write methods to explicitly handl…
Aug 11, 2016
f96f505
Update JSONArray.java
stleary Aug 15, 2016
7232a95
Update JSONObject.java
stleary Aug 15, 2016
7851e9b
revert back changes to Number support
Aug 15, 2016
349a209
Merge remote-tracking branch 'upstream/master' into EnumCleanup
Aug 15, 2016
2f2cd4d
Fix for number output bug.
Aug 17, 2016
ebe69df
Merge pull request #271 from johnjaylward/EnumCleanup
stleary Aug 19, 2016
88f65c5
Merge branch 'master' of github.com:stleary/JSON-java into NumberOutp…
Aug 26, 2016
c24be0e
Merge pull request #274 from johnjaylward/NumberOutputFix
stleary Sep 9, 2016
a2d3b59
Implements unicode escaping similar to JSONObject.
Sep 22, 2016
34652a8
Updates to iterate on code points instead of characters and changes t…
Sep 22, 2016
68f92eb
Adds more javadoc.
Sep 22, 2016
c11e099
Fixes code point output when unescaping code points. XML escapes are …
Sep 22, 2016
f58a0f4
fixes code point appends to string builder
Sep 22, 2016
adb0478
properly unescape tokens in JSONML for reversability.
Sep 22, 2016
fb1db93
Changes encoding to better match the XML spec section 2.2
Sep 29, 2016
e477d70
fixes object comparison
Sep 29, 2016
93ffca3
fixes spacing
Sep 29, 2016
e0616a1
fixing #291
erosb Oct 5, 2016
237376e
Merge pull request #292 from erosb/master
stleary Oct 8, 2016
413bb53
Merge pull request #288 from johnjaylward/XmlEscape
stleary Nov 24, 2016
5ef4f58
[FIX] Update README
omarzina Dec 5, 2016
5ff8b4c
Merge pull request #304 from omarzina/master
stleary Dec 5, 2016
eb806f4
make sure locale independent data is not upper/lowercased incorrectly…
Feb 10, 2017
724fb88
Merge pull request #317 from johnjaylward/fixLocale
stleary Feb 20, 2017
9e0fc5e
Allow user to invoke query and optQuery ,with a JSONPointer,directly
dtalex Feb 25, 2017
2917104
Allow user to invoke query and optQuery ,with a JSONPointer,directly
dtalex Feb 25, 2017
80e2ea2
Merge pull request #324 from dtalex/JSONPointerOnBeans
stleary Mar 28, 2017
f12fa9b
Update LICENSE
stleary Apr 18, 2017
cbd8b18
Update README
stleary May 16, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions CDL.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ of this software and associated documentation files (the "Software"), to deal
* The names for the elements in the JSONObjects can be taken from the names
* in the first row.
* @author JSON.org
* @version 2015-05-01
* @version 2016-05-01
*/
public class CDL {

Expand Down Expand Up @@ -69,7 +69,12 @@ private static String getValue(JSONTokener x) throws JSONException {
for (;;) {
c = x.next();
if (c == q) {
break;
//Handle escaped double-quote
if(x.next() != '\"')
{
x.back();
break;
}
}
if (c == 0 || c == '\n' || c == '\r') {
throw x.syntaxError("Missing close quote '" + q + "'.");
Expand Down
2 changes: 1 addition & 1 deletion Cookie.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
* Convert a web browser cookie specification to a JSONObject and back.
* JSON and Cookies are both notations for name/value pairs.
* @author JSON.org
* @version 2014-05-03
* @version 2015-12-09
*/
public class Cookie {

Expand Down
2 changes: 1 addition & 1 deletion CookieList.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ of this software and associated documentation files (the "Software"), to deal
/**
* Convert a web browser cookie list string to a JSONObject and back.
* @author JSON.org
* @version 2014-05-03
* @version 2015-12-09
*/
public class CookieList {

Expand Down
5 changes: 3 additions & 2 deletions HTTP.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ of this software and associated documentation files (the "Software"), to deal
*/

import java.util.Iterator;
import java.util.Locale;

/**
* Convert an HTTP header to a JSONObject and back.
* @author JSON.org
* @version 2014-05-03
* @version 2015-12-09
*/
public class HTTP {

Expand Down Expand Up @@ -74,7 +75,7 @@ public static JSONObject toJSONObject(String string) throws JSONException {
String token;

token = x.nextToken();
if (token.toUpperCase().startsWith("HTTP")) {
if (token.toUpperCase(Locale.ROOT).startsWith("HTTP")) {

// Response

Expand Down
2 changes: 1 addition & 1 deletion HTTPTokener.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
* The HTTPTokener extends the JSONTokener to provide additional methods
* for the parsing of HTTP headers.
* @author JSON.org
* @version 2014-05-03
* @version 2015-12-09
*/
public class HTTPTokener extends JSONTokener {

Expand Down
130 changes: 117 additions & 13 deletions JSONArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ of this software and associated documentation files (the "Software"), to deal
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Array;
import java.math.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
Expand Down Expand Up @@ -76,7 +78,7 @@ of this software and associated documentation files (the "Software"), to deal
* </ul>
*
* @author JSON.org
* @version 2015-07-22
* @version 2016-08/15
*/
public class JSONArray implements Iterable<Object> {

Expand Down Expand Up @@ -151,13 +153,12 @@ public JSONArray(String source) throws JSONException {
* @param collection
* A Collection.
*/
public JSONArray(Collection<Object> collection) {
public JSONArray(Collection<?> collection) {
this.myArrayList = new ArrayList<Object>();
if (collection != null) {
Iterator<Object> iter = collection.iterator();
while (iter.hasNext()) {
this.myArrayList.add(JSONObject.wrap(iter.next()));
}
for (Object o: collection){
this.myArrayList.add(JSONObject.wrap(o));
}
}
}

Expand Down Expand Up @@ -594,7 +595,9 @@ public <E extends Enum<E>> E optEnum(Class<E> clazz, int index, E defaultValue)
return myE;
}
return Enum.valueOf(clazz, val.toString());
} catch (IllegalArgumentException | NullPointerException e) {
} catch (IllegalArgumentException e) {
return defaultValue;
} catch (NullPointerException e) {
return defaultValue;
}
}
Expand Down Expand Up @@ -746,7 +749,7 @@ public JSONArray put(boolean value) {
* A Collection value.
* @return this.
*/
public JSONArray put(Collection<Object> value) {
public JSONArray put(Collection<?> value) {
this.put(new JSONArray(value));
return this;
}
Expand Down Expand Up @@ -799,7 +802,7 @@ public JSONArray put(long value) {
* A Map value.
* @return this.
*/
public JSONArray put(Map<String, Object> value) {
public JSONArray put(Map<?, ?> value) {
this.put(new JSONObject(value));
return this;
}
Expand Down Expand Up @@ -848,7 +851,7 @@ public JSONArray put(int index, boolean value) throws JSONException {
* @throws JSONException
* If the index is negative or if the value is not finite.
*/
public JSONArray put(int index, Collection<Object> value) throws JSONException {
public JSONArray put(int index, Collection<?> value) throws JSONException {
this.put(index, new JSONArray(value));
return this;
}
Expand Down Expand Up @@ -920,7 +923,7 @@ public JSONArray put(int index, long value) throws JSONException {
* If the index is negative or if the the value is an invalid
* number.
*/
public JSONArray put(int index, Map<String, Object> value) throws JSONException {
public JSONArray put(int index, Map<?, ?> value) throws JSONException {
this.put(index, new JSONObject(value));
return this;
}
Expand Down Expand Up @@ -956,6 +959,80 @@ public JSONArray put(int index, Object value) throws JSONException {
}
return this;
}

/**
* Creates a JSONPointer using an initialization string and tries to
* match it to an item within this JSONArray. For example, given a
* JSONArray initialized with this document:
* <pre>
* [
* {"b":"c"}
* ]
* </pre>
* and this JSONPointer string:
* <pre>
* "/0/b"
* </pre>
* Then this method will return the String "c"
* A JSONPointerException may be thrown from code called by this method.
*
* @param jsonPointer string that can be used to create a JSONPointer
* @return the item matched by the JSONPointer, otherwise null
*/
public Object query(String jsonPointer) {
return query(new JSONPointer(jsonPointer));
}

/**
* Uses a uaer initialized JSONPointer and tries to
* match it to an item whithin this JSONArray. For example, given a
* JSONArray initialized with this document:
* <pre>
* [
* {"b":"c"}
* ]
* </pre>
* and this JSONPointer:
* <pre>
* "/0/b"
* </pre>
* Then this method will return the String "c"
* A JSONPointerException may be thrown from code called by this method.
*
* @param jsonPointer string that can be used to create a JSONPointer
* @return the item matched by the JSONPointer, otherwise null
*/
public Object query(JSONPointer jsonPointer) {
return jsonPointer.queryFrom(this);
}

/**
* Queries and returns a value from this object using {@code jsonPointer}, or
* returns null if the query fails due to a missing key.
*
* @param jsonPointer the string representation of the JSON pointer
* @return the queried value or {@code null}
* @throws IllegalArgumentException if {@code jsonPointer} has invalid syntax
*/
public Object optQuery(String jsonPointer) {
return optQuery(new JSONPointer(jsonPointer));
}

/**
* Queries and returns a value from this object using {@code jsonPointer}, or
* returns null if the query fails due to a missing key.
*
* @param The JSON pointer
* @return the queried value or {@code null}
* @throws IllegalArgumentException if {@code jsonPointer} has invalid syntax
*/
public Object optQuery(JSONPointer jsonPointer) {
try {
return jsonPointer.queryFrom(this);
} catch (JSONPointerException e) {
return null;
}
}

/**
* Remove an index and close the hole.
Expand Down Expand Up @@ -1084,14 +1161,16 @@ public Writer write(Writer writer) throws JSONException {
* <p>
* Warning: This method assumes that the data structure is acyclical.
*
* @param writer
* Writes the serialized JSON
* @param indentFactor
* The number of spaces to add to each level of indentation.
* @param indent
* The indention of the top level.
* @return The writer.
* @throws JSONException
*/
Writer write(Writer writer, int indentFactor, int indent)
public Writer write(Writer writer, int indentFactor, int indent)
throws JSONException {
try {
boolean commanate = false;
Expand Down Expand Up @@ -1127,4 +1206,29 @@ Writer write(Writer writer, int indentFactor, int indent)
throw new JSONException(e);
}
}

/**
* Returns a java.util.List containing all of the elements in this array.
* If an element in the array is a JSONArray or JSONObject it will also
* be converted.
* <p>
* Warning: This method assumes that the data structure is acyclical.
*
* @return a java.util.List containing the elements of this array
*/
public List<Object> toList() {
List<Object> results = new ArrayList<Object>(this.myArrayList.size());
for (Object element : this.myArrayList) {
if (element == null || JSONObject.NULL.equals(element)) {
results.add(null);
} else if (element instanceof JSONArray) {
results.add(((JSONArray) element).toList());
} else if (element instanceof JSONObject) {
results.add(((JSONObject) element).toMap());
} else {
results.add(element);
}
}
return results;
}
}
34 changes: 18 additions & 16 deletions JSONException.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,42 @@
* The JSONException is thrown by the JSON.org classes when things are amiss.
*
* @author JSON.org
* @version 2014-05-03
* @version 2015-12-09
*/
public class JSONException extends RuntimeException {
/** Serialization ID */
private static final long serialVersionUID = 0;
private Throwable cause;

/**
* Constructs a JSONException with an explanatory message.
*
* @param message
* Detail about the reason for the exception.
*/
public JSONException(String message) {
public JSONException(final String message) {
super(message);
}

/**
* Constructs a new JSONException with the specified cause.
* @param cause The cause.
* Constructs a JSONException with an explanatory message and cause.
*
* @param message
* Detail about the reason for the exception.
* @param cause
* The cause.
*/
public JSONException(Throwable cause) {
super(cause.getMessage());
this.cause = cause;
public JSONException(final String message, final Throwable cause) {
super(message, cause);
}

/**
* Returns the cause of this exception or null if the cause is nonexistent
* or unknown.
*
* @return the cause of this exception or null if the cause is nonexistent
* or unknown.
* Constructs a new JSONException with the specified cause.
*
* @param cause
* The cause.
*/
@Override
public Throwable getCause() {
return this.cause;
public JSONException(final Throwable cause) {
super(cause.getMessage(), cause);
}

}
Loading