List of usage examples for com.fasterxml.jackson.core JsonParser getCurrentLocation
public abstract JsonLocation getCurrentLocation();
From source file:com.microsoft.azure.storage.table.ODataUtilities.java
/*** * Reserved for internal use. Asserts that the current token of the parser is the start of an object. * /*w w w . j a v a 2 s . com*/ * @param parser * The {@link JsonParser} whose current token to check. */ protected static void assertIsStartObjectJsonToken(final JsonParser parser) throws JsonParseException { if (!(parser.getCurrentToken() == JsonToken.START_OBJECT)) { throw new JsonParseException(SR.EXPECTED_START_OBJECT, parser.getCurrentLocation()); } }
From source file:org.mashti.jetson.util.JsonParserUtil.java
/** * Consumes the next token from a JSON stream and checks that the token is a {@link JsonToken#START_ARRAY}. * Throws {@link JsonParseException} if the token is not a {@link JsonToken#START_ARRAY}. * * @param parser the parser to read from * @throws IOException Signals that an I/O exception has occurred. */// ww w . java 2s . c o m private static void expectEndArray(final JsonParser parser) throws IOException { if (parser.nextToken() != JsonToken.END_ARRAY) { throw new JsonParseException("expected end array", parser.getCurrentLocation()); } }
From source file:org.mashti.jetson.util.JsonParserUtil.java
/** * Consumes the next token from a JSON stream and checks that the token is a {@link JsonToken#VALUE_NULL}. * Throws {@link JsonParseException} if the token is not a {@link JsonToken#VALUE_NULL}. * * @param parser the parser to read from * @throws IOException Signals that an I/O exception has occurred. *//*from w ww .j av a 2 s. com*/ private static void expectNullValue(final JsonParser parser) throws IOException { if (parser.nextToken() != JsonToken.VALUE_NULL) { throw new JsonParseException("expected null value", parser.getCurrentLocation()); } }
From source file:org.mashti.jetson.util.JsonParserUtil.java
/** * Expects start array./* w w w . j a v a 2 s .co m*/ * * @param parser the parser * @throws IOException Signals that an I/O exception has occurred. */ private static void expectStartArray(final JsonParser parser) throws IOException { if (parser.nextToken() != JsonToken.START_ARRAY) { throw new JsonParseException("expected start array", parser.getCurrentLocation()); } }
From source file:org.mashti.jetson.util.JsonParserUtil.java
/** * Consumes a field name from a JSON stream and checks that the filed name matches the given {@code filed_name}. * Throws {@link JsonParseException} if the consumed field name does not match the given {@code field_name}. * * @param parser the parser to read from * @param field_name the field name to expect * @throws IOException Signals that an I/O exception has occurred. *//*from w w w . j a va2s .c o m*/ public static void expectFieldName(final JsonParser parser, final String field_name) throws IOException { if (!nextFieldName(parser).equals(field_name)) { throw new JsonParseException("expected the field name " + field_name, parser.getCurrentLocation()); } }
From source file:org.mashti.jetson.util.JsonParserUtil.java
/** * Consumes the next token from a JSON stream and checks that the token is a {@link JsonToken#FIELD_NAME}. * Throws {@link JsonParseException} if the token is not a {@link JsonToken#FIELD_NAME}. * * @param parser the parser to read from * @return the field name//from ww w. j a v a 2 s.c o m * @throws IOException Signals that an I/O exception has occurred. */ private static String nextFieldName(final JsonParser parser) throws IOException { if (parser.nextToken() == JsonToken.FIELD_NAME) { return parser.getCurrentName(); } throw new JsonParseException("expected some field name", parser.getCurrentLocation()); }
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.j av a 2 s. c om*/ * @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 www. ja v a2s . co m*/ * @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.addthis.codec.jackson.MissingPropertyException.java
public static MissingPropertyException from(JsonParser jp, Object fromObjectOrClass, String propertyName, Collection<Object> propertyIds) { if (fromObjectOrClass == null) { throw new IllegalArgumentException(); }//from w ww .j av a2 s. co m Class<?> ref; if (fromObjectOrClass instanceof Class<?>) { ref = (Class<?>) fromObjectOrClass; } else { ref = fromObjectOrClass.getClass(); } String msg = "Missing field \"" + propertyName + "\" (class " + ref.getName() + "), marked as required"; MissingPropertyException e = new MissingPropertyException(msg, jp.getCurrentLocation(), ref, propertyName, propertyIds); // but let's also ensure path includes this last (missing) segment e.prependPath(fromObjectOrClass, propertyName); return e; }
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 v a2s . 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()); }