use of org.bson.json.JsonParseException in project spring-data-mongodb by spring-projects.
the class ParameterBindingJsonReader method visitRegularExpressionExtendedJson.
private BsonRegularExpression visitRegularExpressionExtendedJson(final String firstKey) {
Mark extendedJsonMark = new Mark();
try {
verifyToken(JsonTokenType.COLON);
String pattern;
String options = "";
if (firstKey.equals("$regex")) {
pattern = readStringFromExtendedJson();
verifyToken(JsonTokenType.COMMA);
verifyString("$options");
verifyToken(JsonTokenType.COLON);
options = readStringFromExtendedJson();
} else {
options = readStringFromExtendedJson();
verifyToken(JsonTokenType.COMMA);
verifyString("$regex");
verifyToken(JsonTokenType.COLON);
pattern = readStringFromExtendedJson();
}
verifyToken(JsonTokenType.END_OBJECT);
return new BsonRegularExpression(pattern, options);
} catch (JsonParseException e) {
extendedJsonMark.reset();
return null;
}
}
use of org.bson.json.JsonParseException in project spring-data-mongodb by spring-projects.
the class ParameterBindingJsonReader method visitNewRegularExpressionExtendedJson.
private BsonRegularExpression visitNewRegularExpressionExtendedJson() {
verifyToken(JsonTokenType.COLON);
verifyToken(JsonTokenType.BEGIN_OBJECT);
String pattern;
String options = "";
String firstKey = readStringFromExtendedJson();
if (firstKey.equals("pattern")) {
verifyToken(JsonTokenType.COLON);
pattern = readStringFromExtendedJson();
verifyToken(JsonTokenType.COMMA);
verifyString("options");
verifyToken(JsonTokenType.COLON);
options = readStringFromExtendedJson();
} else if (firstKey.equals("options")) {
verifyToken(JsonTokenType.COLON);
options = readStringFromExtendedJson();
verifyToken(JsonTokenType.COMMA);
verifyString("pattern");
verifyToken(JsonTokenType.COLON);
pattern = readStringFromExtendedJson();
} else {
throw new JsonParseException("Expected 't' and 'i' fields in $timestamp document but found " + firstKey);
}
verifyToken(JsonTokenType.END_OBJECT);
verifyToken(JsonTokenType.END_OBJECT);
return new BsonRegularExpression(pattern, options);
}
use of org.bson.json.JsonParseException in project spring-data-mongodb by spring-projects.
the class ParameterBindingJsonReader method visitNumberDoubleExtendedJson.
private Double visitNumberDoubleExtendedJson() {
verifyToken(JsonTokenType.COLON);
Double value;
String doubleAsString = readStringFromExtendedJson();
try {
value = Double.valueOf(doubleAsString);
} catch (NumberFormatException e) {
throw new JsonParseException(format("Exception converting value '%s' to type %s", doubleAsString, Double.class.getName()), e);
}
verifyToken(JsonTokenType.END_OBJECT);
return value;
}
use of org.bson.json.JsonParseException in project spring-data-mongodb by spring-projects.
the class ParameterBindingJsonReader method visitNumberDecimalExtendedJson.
private Decimal128 visitNumberDecimalExtendedJson() {
verifyToken(JsonTokenType.COLON);
Decimal128 value;
String decimal128AsString = readStringFromExtendedJson();
try {
value = Decimal128.parse(decimal128AsString);
} catch (NumberFormatException e) {
throw new JsonParseException(format("Exception converting value '%s' to type %s", decimal128AsString, Decimal128.class.getName()), e);
}
verifyToken(JsonTokenType.END_OBJECT);
return value;
}
use of org.bson.json.JsonParseException in project spring-data-mongodb by spring-projects.
the class ParameterBindingJsonReader method visitTimestampExtendedJson.
private BsonTimestamp visitTimestampExtendedJson() {
verifyToken(JsonTokenType.COLON);
verifyToken(JsonTokenType.BEGIN_OBJECT);
int time;
int increment;
String firstKey = readStringFromExtendedJson();
if (firstKey.equals("t")) {
verifyToken(JsonTokenType.COLON);
time = readIntFromExtendedJson();
verifyToken(JsonTokenType.COMMA);
verifyString("i");
verifyToken(JsonTokenType.COLON);
increment = readIntFromExtendedJson();
} else if (firstKey.equals("i")) {
verifyToken(JsonTokenType.COLON);
increment = readIntFromExtendedJson();
verifyToken(JsonTokenType.COMMA);
verifyString("t");
verifyToken(JsonTokenType.COLON);
time = readIntFromExtendedJson();
} else {
throw new JsonParseException("Expected 't' and 'i' fields in $timestamp document but found " + firstKey);
}
verifyToken(JsonTokenType.END_OBJECT);
verifyToken(JsonTokenType.END_OBJECT);
return new BsonTimestamp(time, increment);
}
Aggregations