[Git][java-team/libjettison-java][upstream] New upstream version 1.4.1
Emmanuel Bourg
gitlab at salsa.debian.org
Sun Jan 17 23:15:44 GMT 2021
Emmanuel Bourg pushed to branch upstream at Debian Java Maintainers / libjettison-java
Commits:
f41bb181 by Emmanuel Bourg at 2021-01-18T00:10:10+01:00
New upstream version 1.4.1
- - - - -
11 changed files:
- README.md
- pom.xml
- src/main/java/org/codehaus/jettison/json/JSONArray.java
- src/main/java/org/codehaus/jettison/json/JSONException.java
- src/main/java/org/codehaus/jettison/json/JSONObject.java
- src/main/java/org/codehaus/jettison/json/JSONTokener.java
- src/main/java/org/codehaus/jettison/json/JSONWriter.java
- src/main/java/org/codehaus/jettison/mapped/Configuration.java
- src/main/java/org/codehaus/jettison/mapped/MappedNamespaceConvention.java
- src/main/java/org/codehaus/jettison/mapped/MappedXMLStreamReader.java
- src/main/java/org/codehaus/jettison/util/StringIndenter.java
Changes:
=====================================
README.md
=====================================
@@ -1,5 +1,5 @@
Jettison is a Java library for converting XML to JSON and vice-versa with the help of StAX (https://en.wikipedia.org/wiki/StAX).
-It implements XMLStreamWriter and XMLStreamReader and supports Mapped and BadgerFish conventions. Latest release is 1.3.7.
+It implements XMLStreamWriter and XMLStreamReader and supports Mapped and BadgerFish conventions. Latest release is 1.4.0.
For example, with a Mapped convention, JAXB processes JAXB beans and emits XMLStreamWriter events which are processed by Jettison
with the XML data being converted to JSON. Likewise, when it reads JSON, it reports XMLStreamReader events for JAXB to populate JAXB
=====================================
pom.xml
=====================================
@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
- <version>1.4.0</version>
+ <version>1.4.1</version>
<packaging>bundle</packaging>
<name>Jettison</name>
<description>A StAX implementation for JSON.</description>
@@ -31,7 +31,7 @@
<connection>scm:git:http://github.com/jettison-json/jettison.git</connection>
<developerConnection>scm:git:https://github.com/jettison-json/jettison.git</developerConnection>
<url>https://github.com/jettison-json/jettison</url>
- <tag>jettison-1.4.0</tag>
+ <tag>jettison-1.4.1</tag>
</scm>
<distributionManagement>
<snapshotRepository>
=====================================
src/main/java/org/codehaus/jettison/json/JSONArray.java
=====================================
@@ -621,7 +621,7 @@ public class JSONArray implements Serializable {
* @return this.
*/
public JSONArray put(long value) {
- put(new Long(value));
+ put(Long.valueOf(value));
return this;
}
@@ -727,7 +727,7 @@ public class JSONArray implements Serializable {
* @throws JSONException If the index is negative.
*/
public JSONArray put(int index, long value) throws JSONException {
- put(index, new Long(value));
+ put(index, Long.valueOf(value));
return this;
}
=====================================
src/main/java/org/codehaus/jettison/json/JSONException.java
=====================================
@@ -21,7 +21,6 @@ package org.codehaus.jettison.json;
* @version 2
*/
public class JSONException extends Exception {
- private Throwable cause;
private int line = -1;
private int column = -1;
/**
@@ -40,11 +39,6 @@ public class JSONException extends Exception {
public JSONException(Throwable t) {
super(t.getMessage(), t);
- this.cause = t;
- }
-
- public Throwable getCause() {
- return this.cause;
}
public int getColumn() {
=====================================
src/main/java/org/codehaus/jettison/json/JSONObject.java
=====================================
@@ -25,6 +25,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.codehaus.jettison.JSONSequenceTooLargeException;
@@ -91,15 +92,15 @@ public class JSONObject implements Serializable {
private static final class Null {
boolean explicitNull;
-
- public Null() {
-
+
+ public Null() {
+
}
- public Null(boolean explicitNull) {
+ public Null(boolean explicitNull) {
this.explicitNull = explicitNull;
}
-
+
/**
* There is only intended to be a single instance of the NULL object,
* so the clone method returns itself.
@@ -128,7 +129,7 @@ public class JSONObject implements Serializable {
public String toString() {
return isExplicitNull() ? null : "null";
}
-
+
public boolean isExplicitNull() {
return explicitNull;
}
@@ -138,7 +139,7 @@ public class JSONObject implements Serializable {
/**
* The hash map where the JSONObject's properties are kept.
*/
- private LinkedHashMap myHashMap;
+ private LinkedHashMap<Object,Object> myHashMap;
private boolean dropRootElement;
private List ignoredElements;
private boolean writeNullAsString = true;
@@ -165,10 +166,10 @@ public class JSONObject implements Serializable {
public JSONObject(List ignoredElements) {
this(false, ignoredElements, true, true);
}
-
- public JSONObject(boolean dropRootElement, List ignoredElements, boolean writeNullAsString,
+
+ public JSONObject(boolean dropRootElement, List ignoredElements, boolean writeNullAsString,
boolean escapeForwardSlash) {
- this.myHashMap = new LinkedHashMap();
+ this.myHashMap = new LinkedHashMap<Object,Object>();
this.dropRootElement = dropRootElement;
this.ignoredElements = ignoredElements;
this.writeNullAsString = writeNullAsString;
@@ -259,21 +260,21 @@ public class JSONObject implements Serializable {
*/
public JSONObject(Map map) {
this.myHashMap = (map == null) ?
- new LinkedHashMap() :
- new LinkedHashMap(map);
+ new LinkedHashMap<Object,Object>() :
+ new LinkedHashMap<Object,Object>(map);
// ensure a pure hierarchy of JSONObjects and JSONArrays
- for (Object k : myHashMap.keySet()) {
- Object v = myHashMap.get(k);
+ for (Entry entry : myHashMap.entrySet()) {
+ Object v = entry.getValue();
if (v instanceof Collection) {
- myHashMap.put(k, new JSONArray((Collection) v));
+ myHashMap.put(entry.getKey(), new JSONArray((Collection) v));
}
if (v instanceof Map) {
- myHashMap.put(k, new JSONObject((Map) v));
+ myHashMap.put(entry.getKey(), new JSONObject((Map) v));
}
- }
+ }
}
-
+
/**
* Construct a JSONObject from an Object, using reflection to find the
* public members. The resulting JSONObject's keys will be the strings
@@ -349,7 +350,7 @@ public class JSONObject implements Serializable {
* @param key A key string.
* @param value An object to be accumulated under the key.
* @return this.
- * @throws JSONException If the key is null or if the current value
+ * @throws JSONException If the key is null or if the current value
* associated with the key is not a JSONArray.
*/
public JSONObject append(String key, Object value)
@@ -359,7 +360,7 @@ public class JSONObject implements Serializable {
if (o == null) {
put(key, new JSONArray().put(value));
} else if (!(o instanceof JSONArray)){
- throw new JSONException("JSONObject[" + key +
+ throw new JSONException("JSONObject[" + key +
"] is not a JSONArray.");
} else {
((JSONArray)o).put(value);
@@ -450,7 +451,7 @@ public class JSONObject implements Serializable {
private double doGetDouble(String key, Object o) throws JSONException {
try {
return o instanceof Number ?
- ((Number)o).doubleValue() :
+ ((Number)o).doubleValue() :
Double.valueOf((String)o).doubleValue();
} catch (Exception e) {
throw new JSONException("JSONObject[" + quote(key) +
@@ -470,7 +471,7 @@ public class JSONObject implements Serializable {
*/
public int getInt(String key) throws JSONException {
return doGetInt(key, get(key));
-
+
}
private int doGetInt(String key, Object o) throws JSONException {
return o instanceof Number ? ((Number)o).intValue() : (int)getDouble(key);
@@ -674,7 +675,7 @@ public class JSONObject implements Serializable {
}
}
-
+
/**
* Put a key/value pair in the JSONObject, where the value will be a
* JSONArray which is produced from a Collection.
@@ -688,7 +689,7 @@ public class JSONObject implements Serializable {
return this;
}
-
+
/**
* Get an optional double associated with a key,
* or NaN if there is no such key or if its value is not a number.
@@ -909,11 +910,11 @@ public class JSONObject implements Serializable {
* @throws JSONException If the key is null.
*/
public JSONObject put(String key, long value) throws JSONException {
- put(key, new Long(value));
+ put(key, Long.valueOf(value));
return this;
}
-
+
/**
* Put a key/value pair in the JSONObject, where the value will be a
* JSONObject which is produced from a Map.
@@ -926,8 +927,8 @@ public class JSONObject implements Serializable {
put(key, new JSONObject(value));
return this;
}
-
-
+
+
/**
* Put a key/value pair in the JSONObject. If the value is null,
* then the key will be removed from the JSONObject if it is present.
@@ -942,11 +943,11 @@ public class JSONObject implements Serializable {
public JSONObject put(String key, Object value) throws JSONException {
return doPut(key, value, -1, false);
}
-
- protected JSONObject doPut(String key,
+
+ protected JSONObject doPut(String key,
Object value,
int threshold,
- boolean checkExistingValue)
+ boolean checkExistingValue)
throws JSONException {
if (key == null) {
throw new JSONException("Null key.");
@@ -995,7 +996,7 @@ public class JSONObject implements Serializable {
return this;
}
-
+
/**
* Produce a string in double quotes with backslash sequences in all the
@@ -1049,6 +1050,12 @@ public class JSONObject implements Serializable {
case '\r':
sb.append("\\r");
break;
+ case '\u2028':
+ sb.append("\\u2028");
+ break;
+ case '\u2029':
+ sb.append("\\u2029");
+ break;
default:
if (c < ' ') {
t = "000" + Integer.toHexString(c);
@@ -1118,7 +1125,7 @@ public class JSONObject implements Serializable {
public int hashCode() {
return myHashMap.hashCode();
}
-
+
@Override
public boolean equals(Object obj) {
if (obj instanceof JSONObject) {
@@ -1127,7 +1134,7 @@ public class JSONObject implements Serializable {
return false;
}
}
-
+
/**
* Make a JSON text of this JSONObject. For compactness, no whitespace
* is added. If this would not result in a syntactically correct JSON text,
@@ -1201,34 +1208,25 @@ public class JSONObject implements Serializable {
Iterator keys = keys();
StringBuilder sb = new StringBuilder("{");
int newindent = indent + indentFactor;
- Object o;
- if (n == 1) {
- o = keys.next();
- sb.append(quote(o.toString(), escapeForwardSlashAlways));
- sb.append(": ");
- sb.append(valueToString(this.myHashMap.get(o), indentFactor,
- indent, escapeForwardSlashAlways));
- } else {
- while (keys.hasNext()) {
- o = keys.next();
- if (sb.length() > 1) {
- sb.append(",\n");
- } else {
- sb.append('\n');
- }
- for (i = 0; i < newindent; i += 1) {
- sb.append(' ');
- }
- sb.append(quote(o.toString()));
- sb.append(": ");
- sb.append(valueToString(this.myHashMap.get(o), indentFactor,
- newindent, escapeForwardSlashAlways));
- }
+ while (keys.hasNext()) {
+ Object o = keys.next();
if (sb.length() > 1) {
+ sb.append(",\n");
+ } else {
sb.append('\n');
- for (i = 0; i < indent; i += 1) {
- sb.append(' ');
- }
+ }
+ for (i = 0; i < newindent; i += 1) {
+ sb.append(' ');
+ }
+ sb.append(quote(o.toString()));
+ sb.append(": ");
+ sb.append(valueToString(this.myHashMap.get(o), indentFactor,
+ newindent, escapeForwardSlashAlways));
+ }
+ if (sb.length() > 1) {
+ sb.append('\n');
+ for (i = 0; i < indent; i += 1) {
+ sb.append(' ');
}
}
sb.append('}');
@@ -1252,21 +1250,21 @@ public class JSONObject implements Serializable {
* with <code>}</code> <small>(right brace)</small>.
* @throws JSONException If the value is or contains an invalid number.
*/
- static String valueToString(Object value, boolean escapeForwardSlash) throws JSONException {
-
+ static String valueToString(Object value, boolean escapeForwardSlash) throws JSONException {
+
if (value == null || value.equals(null)) {
return "null";
}
if (value instanceof JSONString) {
- Object o;
- try {
+ String o;
+ try {
o = ((JSONString)value).toJSONString();
} catch (Exception e) {
throw new JSONException(e);
}
- if (o instanceof String) {
- return (String) o;
- }
+ if (o != null) {
+ return o;
+ }
throw new JSONException("Bad value from toJSONString: " + o);
}
if (value instanceof Number) {
@@ -1300,12 +1298,9 @@ public class JSONObject implements Serializable {
return "null";
}
try {
- if (value instanceof JSONString) {
- Object o = ((JSONString)value).toJSONString();
- if (o instanceof String) {
- return (String)o;
- }
- }
+ if (value instanceof JSONString) {
+ return ((JSONString)value).toJSONString();
+ }
} catch (Exception e) {
/* forget about it */
}
@@ -1338,19 +1333,19 @@ public class JSONObject implements Serializable {
public Writer write(Writer writer) throws JSONException {
try {
int hashMapSize = this.myHashMap.size();
-
+
boolean dropObjectKeyName = false;
if (hashMapSize == 1) {
- dropObjectKeyName = dropRootElement
+ dropObjectKeyName = dropRootElement
|| ignoredElements != null && ignoredElements.contains(keys().next());
}
-
+
if (!dropObjectKeyName) {
writer.write('{');
}
boolean b = false;
-
+
Iterator keys = keys();
while (keys.hasNext()) {
if (b) {
@@ -1358,17 +1353,17 @@ public class JSONObject implements Serializable {
}
String k = keys.next().toString();
Object v = this.myHashMap.get(k);
-
+
boolean mayBeDropSimpleElement = false;
if (!dropObjectKeyName) {
- mayBeDropSimpleElement = hashMapSize > 1
+ mayBeDropSimpleElement = hashMapSize > 1
&& ignoredElements != null && ignoredElements.contains(k);
if (!mayBeDropSimpleElement) {
writer.write(quote(k, escapeForwardSlashAlways));
writer.write(':');
}
}
-
+
if (v instanceof JSONObject) {
((JSONObject)v).write(writer);
} else if (v instanceof JSONArray) {
@@ -1388,7 +1383,7 @@ public class JSONObject implements Serializable {
throw new JSONException(e);
}
}
-
+
public boolean isEscapeForwardSlashAlways() {
return escapeForwardSlashAlways;
}
@@ -1396,4 +1391,8 @@ public class JSONObject implements Serializable {
public void setEscapeForwardSlashAlways(boolean escapeForwardSlashAlways) {
this.escapeForwardSlashAlways = escapeForwardSlashAlways;
}
-}
\ No newline at end of file
+
+ public Map toMap() {
+ return Collections.unmodifiableMap(myHashMap);
+ }
+}
=====================================
src/main/java/org/codehaus/jettison/json/JSONTokener.java
=====================================
@@ -392,10 +392,10 @@ public class JSONTokener {
}
}
try {
- return new Integer(s);
+ return Integer.valueOf(s);
} catch (Exception e) {
try {
- return new Long(s);
+ return Long.valueOf(s);
} catch (Exception f) {
try {
return new Double(s);
=====================================
src/main/java/org/codehaus/jettison/json/JSONWriter.java
=====================================
@@ -92,7 +92,7 @@ public class JSONWriter {
*/
private int top;
- /**kue
+ /**
* The writer that will receive the output.
*/
protected Writer writer;
@@ -140,7 +140,7 @@ public class JSONWriter {
/**
* Begin appending a new array. All values until the balancing
* <code>endArray</code> will be appended to this array. The
- * <code>endArray</code> method must be called to mark the array's end.kue
+ * <code>endArray</code> method must be called to mark the array's end.
* @return this
* @throws JSONException If the nesting is too deep, or if the object is
* started in the wrong place (for example as a key or after the end of the
=====================================
src/main/java/org/codehaus/jettison/mapped/Configuration.java
=====================================
@@ -75,6 +75,7 @@ public class Configuration {
private String attributeKey = "@";
private boolean ignoreNamespaces;
private boolean dropRootElement;
+ private boolean rootElementArrayWrapper = true;
private Set primitiveArrayKeys = Collections.EMPTY_SET;
private boolean writeNullAsString = true;
private boolean readNullAsString;
@@ -169,7 +170,14 @@ public class Configuration {
public void setDropRootElement(boolean dropRootElement) {
this.dropRootElement = dropRootElement;
}
+ public boolean isRootElementArrayWrapper() {
+ return rootElementArrayWrapper;
+ }
+ public void setRootElementArrayWrapper(boolean rootElementArrayWrapper) {
+ this.rootElementArrayWrapper = rootElementArrayWrapper;
+ }
+
public boolean isWriteNullAsString() {
return writeNullAsString;
}
=====================================
src/main/java/org/codehaus/jettison/mapped/MappedNamespaceConvention.java
=====================================
@@ -51,6 +51,7 @@ public class MappedNamespaceConvention implements Convention, NamespaceContext {
private Set<?> primitiveArrayKeys;
private boolean dropRootElement;
private boolean writeNullAsString = true;
+ private boolean rootElementArrayWrapper = true;
private boolean ignoreEmptyArrayValues;
private boolean readNullAsString;
private boolean escapeForwardSlashAlways;
@@ -66,6 +67,7 @@ public class MappedNamespaceConvention implements Convention, NamespaceContext {
this.supressAtAttributes = config.isSupressAtAttributes();
this.ignoreNamespaces = config.isIgnoreNamespaces();
this.dropRootElement = config.isDropRootElement();
+ this.rootElementArrayWrapper = config.isRootElementArrayWrapper();
this.attributeKey = config.getAttributeKey();
this.primitiveArrayKeys = config.getPrimitiveArrayKeys();
this.ignoredElements = config.getIgnoredElements();
@@ -135,6 +137,25 @@ public class MappedNamespaceConvention implements Convention, NamespaceContext {
n.setNamespace( prefix, uri );
}
}
+ // With the 1.0 release, the default behavior was to treat an @xmlns
+ // JSON field name (without a namespace prefix), as the attribute for
+ // the default namespace URI. During JSON->XML serialization, this
+ // default behavior resulted in an xmlns (without a namespace prefix)
+ // attribute appearing on the applicable element, with the default
+ // namespace uri as it's value.
+ //
+ // The code refactoring in this processAttributesAndNamespaces
+ // method back in the 2.0 release, no longer assigns the default
+ // namespace URI to the xmlns (without a namespace prefix) during JSON->XML
+ // serialization, which in some cases is causing unmarshaling issues.
+ // Putting in the following conditional check, restores the previous
+ // default behavior, without breaking anything added during the earlier
+ // refactoring exercise.
+ if (o instanceof String) {
+ String uri = o.toString();
+ QName name = new QName( XMLConstants.DEFAULT_NS_PREFIX, k);
+ n.setAttribute(name, uri);
+ }
}
else {
String strValue = o == null ? null : o.toString();
@@ -313,10 +334,13 @@ public class MappedNamespaceConvention implements Convention, NamespaceContext {
public boolean isDropRootElement() {
return dropRootElement;
}
+ public boolean isRootElementArrayWrapper() {
+ return rootElementArrayWrapper;
+ }
public List<?> getIgnoredElements() {
- return ignoredElements;
- }
- public boolean isWriteNullAsString() {
+ return ignoredElements;
+ }
+ public boolean isWriteNullAsString() {
return writeNullAsString;
}
public boolean isReadNullAsString() {
=====================================
src/main/java/org/codehaus/jettison/mapped/MappedXMLStreamReader.java
=====================================
@@ -50,7 +50,11 @@ public class MappedXMLStreamReader extends AbstractXMLStreamReader {
if (top instanceof JSONObject) {
this.node = new Node(null, rootName, (JSONObject)top, convention);
} else if (top instanceof JSONArray && !(((JSONArray)top).length() == 1 && ((JSONArray)top).get(0).equals(""))) {
- this.node = new Node(null, rootName, obj, convention);
+ if (con.isRootElementArrayWrapper()) {
+ this.node = new Node(null, rootName, obj, convention);
+ } else {
+ this.node = new Node(null, rootName, ((JSONArray)top).getJSONObject(0), convention);
+ }
} else {
node = new Node(rootName, convention);
convention.processAttributesAndNamespaces(node, obj);
=====================================
src/main/java/org/codehaus/jettison/util/StringIndenter.java
=====================================
@@ -78,7 +78,7 @@ public class StringIndenter {
return null;
}
String resultString = this.result.toString();
- return resultString == null ? null : resultString.trim();
+ return resultString.trim();
}
/**
View it on GitLab: https://salsa.debian.org/java-team/libjettison-java/-/commit/f41bb1810b6baaa63659e94cddb5b693998ddce0
--
View it on GitLab: https://salsa.debian.org/java-team/libjettison-java/-/commit/f41bb1810b6baaa63659e94cddb5b693998ddce0
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20210117/8f346cec/attachment.html>
More information about the pkg-java-commits
mailing list