--- /dev/null
+/**
+ * Macaco
+ * Copyright (c) 2009-2015 Marco Zanon <info@marcozanon.com>.
+ * Released under MIT license (see LICENSE for details).
+ */
+
+package com.marcozanon.macaco.json;
+
+@SuppressWarnings("serial")
+public class MInvalidJsonValueException extends MJsonException {
+
+ /* */
+
+ public MInvalidJsonValueException() {
+ super();
+ }
+
+ public MInvalidJsonValueException(String message) {
+ super(message);
+ }
+
+ public MInvalidJsonValueException(Throwable error) {
+ super(error);
+ }
+
+ public MInvalidJsonValueException(String message, Throwable error) {
+ super(message, error);
+ }
+
+}
+++ /dev/null
-/**
- * Macaco
- * Copyright (c) 2009-2015 Marco Zanon <info@marcozanon.com>.
- * Released under MIT license (see LICENSE for details).
- */
-
-package com.marcozanon.macaco.json;
-
-@SuppressWarnings("serial")
-public class MInvalidValueJsonException extends MJsonException {
-
- /* */
-
- public MInvalidValueJsonException() {
- super();
- }
-
- public MInvalidValueJsonException(String message) {
- super(message);
- }
-
- public MInvalidValueJsonException(Throwable error) {
- super(error);
- }
-
- public MInvalidValueJsonException(String message, Throwable error) {
- super(message, error);
- }
-
-}
/* */
- public MJsonArray() throws MInvalidValueJsonException {
+ public MJsonArray() throws MInvalidJsonValueException {
this("[]");
}
- public MJsonArray(String x) throws MInvalidValueJsonException {
+ public MJsonArray(String x) throws MInvalidJsonValueException {
super();
//
this.parseString(x);
try {
tmpMJsonArray = new MJsonArray(this.getJsonValue());
}
- catch (MInvalidValueJsonException exception) { // cannot happen
+ catch (MInvalidJsonValueException exception) { // cannot happen
}
return tmpMJsonArray;
}
testValue.parseString(x.substring(0, position + 1));
return position + 1;
}
- catch (MInvalidValueJsonException exception) {
+ catch (MInvalidJsonValueException exception) {
position = x.indexOf("]", position + 1);
}
}
return 0;
}
- public void parseString(String x) throws MInvalidValueJsonException {
+ public void parseString(String x) throws MInvalidJsonValueException {
if (MText.isBlank(x)) {
throw new IllegalArgumentException("Invalid 'x': null or empty.");
}
//
if ((2 > x.length()) || ('[' != x.charAt(0)) || (']' != x.charAt(x.length() - 1))) {
- throw new MInvalidValueJsonException(String.format("Invalid 'x': %s: must begin and end with square brackets.", x));
+ throw new MInvalidJsonValueException(String.format("Invalid 'x': %s: must begin and end with square brackets.", x));
}
String y = x.substring(1, x.length() - 1);
int parsingPosition = 0;
parsingMode = MJsonArray.ParsingMode.ERROR;
}
if (MJsonArray.ParsingMode.ERROR == parsingMode) {
- throw new MInvalidValueJsonException(String.format("Invalid 'x': %s: not a Json array.", x));
+ throw new MInvalidJsonValueException(String.format("Invalid 'x': %s: not a Json array.", x));
}
}
/* */
- public MJsonBoolean() throws MInvalidValueJsonException {
+ public MJsonBoolean() throws MInvalidJsonValueException {
this("false");
}
- public MJsonBoolean(String x) throws MInvalidValueJsonException {
+ public MJsonBoolean(String x) throws MInvalidJsonValueException {
super();
//
this.parseString(x);
try {
tmpMJsonBoolean = new MJsonBoolean(this.getJsonValue());
}
- catch (MInvalidValueJsonException exception) { // cannot happen
+ catch (MInvalidJsonValueException exception) { // cannot happen
}
return tmpMJsonBoolean;
}
return 0;
}
- public void parseString(String x) throws MInvalidValueJsonException {
+ public void parseString(String x) throws MInvalidJsonValueException {
if (MText.isBlank(x)) {
throw new IllegalArgumentException("Invalid 'x': null or empty.");
}
//
if ((!"true".equals(x)) && (!"false".equals(x))) {
- throw new MInvalidValueJsonException(String.format("Invalid 'x': %s: not a Json boolean.", x));
+ throw new MInvalidJsonValueException(String.format("Invalid 'x': %s: not a Json boolean.", x));
}
this.setValue(Boolean.valueOf(x));
}
/* */
- public MJsonNull() throws MInvalidValueJsonException {
+ public MJsonNull() throws MInvalidJsonValueException {
this("null");
}
- public MJsonNull(String x) throws MInvalidValueJsonException {
+ public MJsonNull(String x) throws MInvalidJsonValueException {
super();
//
this.parseString(x);
try {
tmpMJsonNull = new MJsonNull(this.getJsonValue());
}
- catch (MInvalidValueJsonException exception) { // cannot happen
+ catch (MInvalidJsonValueException exception) { // cannot happen
}
return tmpMJsonNull;
}
return 0;
}
- public void parseString(String x) throws MInvalidValueJsonException {
+ public void parseString(String x) throws MInvalidJsonValueException {
if (MText.isBlank(x)) {
throw new IllegalArgumentException("Invalid 'x': null or empty.");
}
//
if (!"null".equals(x)) {
- throw new MInvalidValueJsonException(String.format("Invalid 'x': %s: not a Json null.", x));
+ throw new MInvalidJsonValueException(String.format("Invalid 'x': %s: not a Json null.", x));
}
}
/* */
- public MJsonNumber() throws MInvalidValueJsonException {
+ public MJsonNumber() throws MInvalidJsonValueException {
this("0");
}
- public MJsonNumber(String x) throws MInvalidValueJsonException {
+ public MJsonNumber(String x) throws MInvalidJsonValueException {
super();
//
this.parseString(x);
try {
tmpMJsonNumber = new MJsonNumber(this.getJsonValue());
}
- catch (MInvalidValueJsonException exception) { // cannot happen
+ catch (MInvalidJsonValueException exception) { // cannot happen
}
return tmpMJsonNumber;
}
return validPosition;
}
- public void parseString(String x) throws MInvalidValueJsonException {
+ public void parseString(String x) throws MInvalidJsonValueException {
if (MText.isBlank(x)) {
throw new IllegalArgumentException("Invalid 'x': null or empty.");
}
y = new BigDecimal(x);
}
catch (NumberFormatException exception) {
- throw new MInvalidValueJsonException(String.format("Invalid 'x': %s: not a Json number.", x)); // no need to propagate exception
+ throw new MInvalidJsonValueException(String.format("Invalid 'x': %s: not a Json number.", x)); // no need to propagate exception
}
this.setValue(y);
}
/* */
- public MJsonObject() throws MInvalidValueJsonException {
+ public MJsonObject() throws MInvalidJsonValueException {
this("{}");
}
- public MJsonObject(String x) throws MInvalidValueJsonException {
+ public MJsonObject(String x) throws MInvalidJsonValueException {
super();
//
this.parseString(x);
try {
tmpMJsonObject = new MJsonObject(this.getJsonValue());
}
- catch (MInvalidValueJsonException exception) { // cannot happen
+ catch (MInvalidJsonValueException exception) { // cannot happen
}
return tmpMJsonObject;
}
testValue.parseString(x.substring(0, position + 1));
return position + 1;
}
- catch (MInvalidValueJsonException exception) {
+ catch (MInvalidJsonValueException exception) {
position = x.indexOf("}", position + 1);
}
}
return 0;
}
- public void parseString(String x) throws MInvalidValueJsonException {
+ public void parseString(String x) throws MInvalidJsonValueException {
if (MText.isBlank(x)) {
throw new IllegalArgumentException("Invalid 'x': null or empty.");
}
//
if ((2 > x.length()) || ('{' != x.charAt(0)) || ('}' != x.charAt(x.length() - 1))) {
- throw new MInvalidValueJsonException(String.format("Invalid 'x': %s: must begin and end with curly brackets.", x));
+ throw new MInvalidJsonValueException(String.format("Invalid 'x': %s: must begin and end with curly brackets.", x));
}
String y = x.substring(1, x.length() - 1);
int parsingPosition = 0;
parsingMode = MJsonObject.ParsingMode.ERROR;
}
if (MJsonObject.ParsingMode.ERROR == parsingMode) {
- throw new MInvalidValueJsonException(String.format("Invalid 'x': %s: not a Json object.", x));
+ throw new MInvalidJsonValueException(String.format("Invalid 'x': %s: not a Json object.", x));
}
}
/* */
- public MJsonString() throws MInvalidValueJsonException {
+ public MJsonString() throws MInvalidJsonValueException {
this("\"\"");
}
- public MJsonString(String x) throws MInvalidValueJsonException {
+ public MJsonString(String x) throws MInvalidJsonValueException {
this(x, false);
}
- public MJsonString(String x, boolean extendedEscapeMode) throws MInvalidValueJsonException {
+ public MJsonString(String x, boolean extendedEscapeMode) throws MInvalidJsonValueException {
super();
//
this.setExtendedEscapeMode(extendedEscapeMode);
try {
tmpMJsonString = new MJsonString(this.getJsonValue());
}
- catch (MInvalidValueJsonException exception) { // cannot happen
+ catch (MInvalidJsonValueException exception) { // cannot happen
}
return tmpMJsonString;
}
return y.toString();
}
- protected static String getUnescapedString(String x) throws MInvalidValueJsonException {
+ protected static String getUnescapedString(String x) throws MInvalidJsonValueException {
if (null == x) {
throw new IllegalArgumentException("Invalid 'x': null.");
}
}
else if (x.indexOf("\\u", i) == i) {
if ((i + 2 + 4) > x.length()) {
- throw new MInvalidValueJsonException(String.format("Invalid 'x': %s: not a Json string.", x));
+ throw new MInvalidJsonValueException(String.format("Invalid 'x': %s: not a Json string.", x));
}
else {
int ch = -1;
if ((0xD800 <= ch) && (0xDBFF >= ch)) {
i++;
if (x.indexOf("\\u", i) != i) {
- throw new MInvalidValueJsonException(String.format("Invalid 'x': %s: not a Json string.", x));
+ throw new MInvalidJsonValueException(String.format("Invalid 'x': %s: not a Json string.", x));
}
else if ((i + 2 + 4) > x.length()) {
- throw new MInvalidValueJsonException(String.format("Invalid 'x': %s: not a Json string.", x));
+ throw new MInvalidJsonValueException(String.format("Invalid 'x': %s: not a Json string.", x));
}
else {
int cl = -1;
cl = Integer.parseInt(x.substring(i + 2, i + 2 + 4), 16);
i += 5;
if ((0xDC00 >= cl) || (0xDFFF <= cl)) {
- throw new MInvalidValueJsonException(String.format("Invalid 'x': %s: not a Json string.", x));
+ throw new MInvalidJsonValueException(String.format("Invalid 'x': %s: not a Json string.", x));
}
int c = ((ch - 0xD800) << 10) + (cl - 0xDC00) + 0x010000;
y.appendCodePoint(c);
}
catch (NumberFormatException exception) {
- throw new MInvalidValueJsonException(String.format("Invalid 'x': %s: not a Json string.", x)); // no need to propagate exception
+ throw new MInvalidJsonValueException(String.format("Invalid 'x': %s: not a Json string.", x)); // no need to propagate exception
}
}
}
}
}
catch (NumberFormatException exception) {
- throw new MInvalidValueJsonException(String.format("Invalid 'x': %s: not a Json string.", x)); // no need to propagate exception
+ throw new MInvalidJsonValueException(String.format("Invalid 'x': %s: not a Json string.", x)); // no need to propagate exception
}
}
}
return (quotationMarkPosition + 1) + 1;
}
- public void parseString(String x) throws MInvalidValueJsonException {
+ public void parseString(String x) throws MInvalidJsonValueException {
if (MText.isBlank(x)) {
throw new IllegalArgumentException("Invalid 'x': null or empty.");
}
//
if ((2 > x.length()) || ('"' != x.charAt(0)) || ('"' != x.charAt(x.length() - 1))) {
- throw new MInvalidValueJsonException(String.format("Invalid 'x': %s: not a Json string.", x));
+ throw new MInvalidJsonValueException(String.format("Invalid 'x': %s: not a Json string.", x));
}
String y = x.substring(1, x.length() - 1);
if (-1 < y.replaceAll("\\\\\"", "__").indexOf("\"")) {
- throw new MInvalidValueJsonException(String.format("Invalid 'x': %s: not a Json string.", x));
+ throw new MInvalidJsonValueException(String.format("Invalid 'x': %s: not a Json string.", x));
}
this.setValue(MJsonString.getUnescapedString(y));
}