mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
Merge pull request #345 from johnjaylward/BetterErrorHandling
Adds JSONException for write value errors
This commit is contained in:
commit
c9ae1f17d7
2 changed files with 26 additions and 8 deletions
|
@ -1384,8 +1384,12 @@ public class JSONArray implements Iterable<Object> {
|
||||||
writer.write('[');
|
writer.write('[');
|
||||||
|
|
||||||
if (length == 1) {
|
if (length == 1) {
|
||||||
JSONObject.writeValue(writer, this.myArrayList.get(0),
|
try {
|
||||||
indentFactor, indent);
|
JSONObject.writeValue(writer, this.myArrayList.get(0),
|
||||||
|
indentFactor, indent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new JSONException("Unable to write JSONArray value at index: 0", e);
|
||||||
|
}
|
||||||
} else if (length != 0) {
|
} else if (length != 0) {
|
||||||
final int newindent = indent + indentFactor;
|
final int newindent = indent + indentFactor;
|
||||||
|
|
||||||
|
@ -1397,8 +1401,12 @@ public class JSONArray implements Iterable<Object> {
|
||||||
writer.write('\n');
|
writer.write('\n');
|
||||||
}
|
}
|
||||||
JSONObject.indent(writer, newindent);
|
JSONObject.indent(writer, newindent);
|
||||||
JSONObject.writeValue(writer, this.myArrayList.get(i),
|
try {
|
||||||
indentFactor, newindent);
|
JSONObject.writeValue(writer, this.myArrayList.get(i),
|
||||||
|
indentFactor, newindent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new JSONException("Unable to write JSONArray value at index: " + i, e);
|
||||||
|
}
|
||||||
commanate = true;
|
commanate = true;
|
||||||
}
|
}
|
||||||
if (indentFactor > 0) {
|
if (indentFactor > 0) {
|
||||||
|
|
|
@ -2240,12 +2240,17 @@ public class JSONObject {
|
||||||
|
|
||||||
if (length == 1) {
|
if (length == 1) {
|
||||||
final Entry<String,?> entry = this.entrySet().iterator().next();
|
final Entry<String,?> entry = this.entrySet().iterator().next();
|
||||||
writer.write(quote(entry.getKey()));
|
final String key = entry.getKey();
|
||||||
|
writer.write(quote(key));
|
||||||
writer.write(':');
|
writer.write(':');
|
||||||
if (indentFactor > 0) {
|
if (indentFactor > 0) {
|
||||||
writer.write(' ');
|
writer.write(' ');
|
||||||
}
|
}
|
||||||
writeValue(writer, entry.getValue(), indentFactor, indent);
|
try{
|
||||||
|
writeValue(writer, entry.getValue(), indentFactor, indent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new JSONException("Unable to write JSONObject value for key: " + key, e);
|
||||||
|
}
|
||||||
} else if (length != 0) {
|
} else if (length != 0) {
|
||||||
final int newindent = indent + indentFactor;
|
final int newindent = indent + indentFactor;
|
||||||
for (final Entry<String,?> entry : this.entrySet()) {
|
for (final Entry<String,?> entry : this.entrySet()) {
|
||||||
|
@ -2256,12 +2261,17 @@ public class JSONObject {
|
||||||
writer.write('\n');
|
writer.write('\n');
|
||||||
}
|
}
|
||||||
indent(writer, newindent);
|
indent(writer, newindent);
|
||||||
writer.write(quote(entry.getKey()));
|
final String key = entry.getKey();
|
||||||
|
writer.write(quote(key));
|
||||||
writer.write(':');
|
writer.write(':');
|
||||||
if (indentFactor > 0) {
|
if (indentFactor > 0) {
|
||||||
writer.write(' ');
|
writer.write(' ');
|
||||||
}
|
}
|
||||||
writeValue(writer, entry.getValue(), indentFactor, newindent);
|
try {
|
||||||
|
writeValue(writer, entry.getValue(), indentFactor, newindent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new JSONException("Unable to write JSONObject value for key: " + key, e);
|
||||||
|
}
|
||||||
commanate = true;
|
commanate = true;
|
||||||
}
|
}
|
||||||
if (indentFactor > 0) {
|
if (indentFactor > 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue