Search in sources :

Example 16 with JsonParseException

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;
    }
}
Also used : String(java.lang.String) JsonParseException(org.bson.json.JsonParseException)

Example 17 with JsonParseException

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);
}
Also used : String(java.lang.String) JsonParseException(org.bson.json.JsonParseException)

Example 18 with JsonParseException

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;
}
Also used : String(java.lang.String) JsonParseException(org.bson.json.JsonParseException)

Example 19 with JsonParseException

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;
}
Also used : Decimal128(org.bson.types.Decimal128) String(java.lang.String) JsonParseException(org.bson.json.JsonParseException)

Example 20 with JsonParseException

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);
}
Also used : String(java.lang.String) JsonParseException(org.bson.json.JsonParseException)

Aggregations

JsonParseException (org.bson.json.JsonParseException)26 String (java.lang.String)19 Date (java.util.Date)4 SimpleDateFormat (java.text.SimpleDateFormat)3 DateFormat (java.text.DateFormat)2 ParsePosition (java.text.ParsePosition)2 Decimal128 (org.bson.types.Decimal128)2 MaxKey (org.bson.types.MaxKey)2 MinKey (org.bson.types.MinKey)2 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)2 Query (org.springframework.data.mongodb.core.query.Query)2 TextCriteria (org.springframework.data.mongodb.core.query.TextCriteria)2 RepositoryQuery (org.springframework.data.repository.query.RepositoryQuery)2 ReturnedType (org.springframework.data.repository.query.ReturnedType)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 SystemException (com.torodb.core.exceptions.SystemException)1 Calendar (java.util.Calendar)1 Map (java.util.Map)1