Example usage for com.fasterxml.jackson.core JsonParseException JsonParseException

List of usage examples for com.fasterxml.jackson.core JsonParseException JsonParseException

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonParseException JsonParseException.

Prototype

public JsonParseException(String msg, JsonLocation loc) 

Source Link

Usage

From source file:com.microsoft.azure.storage.core.JsonUtilities.java

/***
 * Reserved for internal use. Asserts that the current name of the parser equals the expected value
 * //  ww w.ja  v  a  2s .c o m
 * @param parser
 *            The {@link JsonParser} whose current token to check.
 * @param expectedValue
 *            The expected current name of the parser's current token.
 */
public static void assertIsExpectedFieldName(final JsonParser parser, final String expectedValue)
        throws JsonParseException, IOException {
    final String actualValue = parser.getCurrentName();
    if (expectedValue == null) {
        if (actualValue != null) {
            throw new JsonParseException(String.format(SR.UNEXPECTED_FIELD_NAME, expectedValue, actualValue),
                    parser.getCurrentLocation());
        }
    } else {
        if (!expectedValue.equals(actualValue)) {
            throw new JsonParseException(String.format(SR.UNEXPECTED_FIELD_NAME, expectedValue, actualValue),
                    parser.getCurrentLocation());
        }
    }
}

From source file:com.microsoft.azure.storage.table.ODataUtilities.java

/***
 * Reserved for internal use. Asserts that the current name of the parser equals the expected value
 * /*from  w  w w  .ja va  2  s.  com*/
 * @param parser
 *            The {@link JsonParser} whose current token to check.
 * @param expectedValue
 *            The expected current name of the parser's current token.
 */
protected static void assertIsExpectedFieldName(final JsonParser parser, final String expectedValue)
        throws JsonParseException, IOException {
    final String actualValue = parser.getCurrentName();
    if (expectedValue == null) {
        if (actualValue != null) {
            throw new JsonParseException(String.format(SR.UNEXPECTED_FIELD_NAME, expectedValue, actualValue),
                    parser.getCurrentLocation());
        }
    } else {
        if (!expectedValue.equals(actualValue)) {
            throw new JsonParseException(String.format(SR.UNEXPECTED_FIELD_NAME, expectedValue, actualValue),
                    parser.getCurrentLocation());
        }
    }
}

From source file:com.google.openrtb.json.OpenRtbJsonUtils.java

/**
 * Starts an Object, skipping the '{' token, and if necessary a field name before it.
 *//*from ww  w .  ja va  2  s  .c o m*/
public static void startObject(JsonParser par) throws IOException {
    JsonToken token = par.getCurrentToken();
    if (token == null || token == JsonToken.FIELD_NAME) {
        token = par.nextToken();
    }
    if (token == JsonToken.START_OBJECT) {
        par.nextToken();
    } else {
        throw new JsonParseException(par, "Expected start of object");
    }
}

From source file:org.mashti.jetson.util.JsonParserUtil.java

/**
 * Consumes a field name from a JSON stream and checks that the filed name matches one of the given {@code filed_names}.
 * Throws {@link JsonParseException} if the consumed field name does not match any of the given {@code field_names}.
 *
 * @param parser the parser to read from
 * @param field_names the field names to match
 * @return the matched field name/*from   w w  w. j a va2 s  . c  o m*/
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static String expectFieldNames(final JsonParser parser, final String... field_names) throws IOException {

    final String next_field_name = nextFieldName(parser);
    for (final String field_name : field_names) {
        if (next_field_name.equals(field_name)) {
            return next_field_name;
        }
    }
    throw new JsonParseException("expected one of field names " + Arrays.toString(field_names),
            parser.getCurrentLocation());
}

From source file:com.microsoft.azure.storage.core.JsonUtilities.java

/***
 * Reserved for internal use. Asserts that the current token of the parser is a field name.
 * /*w w  w.j  a  va 2 s  .c o m*/
 * @param parser
 *            The {@link JsonParser} whose current token to check.
 */
public static void assertIsFieldNameJsonToken(final JsonParser parser) throws JsonParseException {
    if (!(parser.getCurrentToken() == JsonToken.FIELD_NAME)) {
        throw new JsonParseException(SR.EXPECTED_A_FIELD_NAME, parser.getCurrentLocation());
    }
}

From source file:com.microsoft.azure.storage.table.ODataUtilities.java

/***
 * Reserved for internal use. Asserts that the current token of the parser is a field name.
 * /*from ww  w  .j  a  va  2s . com*/
 * @param parser
 *            The {@link JsonParser} whose current token to check.
 */
protected static void assertIsFieldNameJsonToken(final JsonParser parser) throws JsonParseException {
    if (!(parser.getCurrentToken() == JsonToken.FIELD_NAME)) {
        throw new JsonParseException(SR.EXPECTED_A_FIELD_NAME, parser.getCurrentLocation());
    }
}

From source file:es.logongas.iothome.agent.http.DateDeserializer.java

@Override
public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException, JsonProcessingException {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");

    try {//from w ww  . j a va  2  s.co m
        return sdf.parse(jsonParser.getText());
    } catch (ParseException ex) {
        throw new JsonParseException("El formato de la fecha '" + jsonParser.getText() + "' no es correcto",
                JsonLocation.NA);
    }
}

From source file:org.springframework.social.bitbucket.api.impl.UTCDateDeserializer.java

@Override
public Date deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    try {/*from   w  ww  . j av a2 s  .co m*/
        SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH);
        dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
        return dateFormat.parse(jp.getText());
    } catch (ParseException e) {
        throw new JsonParseException("Can't parse date : " + jp.getText(), jp.getCurrentLocation());
    }
}

From source file:es.logongas.ix3.web.json.impl.DateDeserializer.java

@Override
public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException, JsonProcessingException {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");

    try {// w  w w  . ja v a 2  s .c  o m
        return sdf.parse(jsonParser.getText());
    } catch (ParseException ex) {
        try {
            long numericDate = Long.parseLong(jsonParser.getText());
            return new Date(numericDate);
        } catch (NumberFormatException ex2) {
            throw new JsonParseException("El formato de la fecha '" + jsonParser.getText() + "' no es correcto",
                    JsonLocation.NA);
        }
    }
}

From source file:ca.ualberta.physics.cssdp.util.JSONDateTimeDeserializer.java

@Override
public DateTime deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    try {//  w  w  w.ja v  a2s .c  o  m
        return ISODateTimeFormat.dateTimeParser().parseDateTime(jp.getText());
    } catch (Exception e) {
        e.printStackTrace();
        throw new JsonParseException(e.getMessage(), jp.getCurrentLocation());
    }
}