List of usage examples for com.fasterxml.jackson.core JsonToken START_OBJECT
JsonToken START_OBJECT
To view the source code for com.fasterxml.jackson.core JsonToken START_OBJECT.
Click Source Link
From source file:com.basho.riak.client.raw.http.NamedErlangFunctionDeserializer.java
@Override public NamedErlangFunction deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken token = jp.getCurrentToken(); if (JsonToken.START_OBJECT.equals(token)) { String mod = null;/*from ww w . j av a 2 s . c o m*/ String fun = null; while (!JsonToken.END_OBJECT.equals(token)) { String field = jp.getCurrentName(); if (Constants.FL_SCHEMA_FUN_MOD.equals(field)) { jp.nextToken(); mod = jp.getText(); } else if (Constants.FL_SCHEMA_FUN_FUN.equals(field)) { jp.nextToken(); fun = jp.getText(); } token = jp.nextToken(); } if (mod != null && fun != null) { return new NamedErlangFunction(mod, fun); } else { return null; } } throw ctxt.mappingException(NamedErlangFunction.class); }
From source file:org.springframework.security.oauth2.common.exceptions.OAuth2ExceptionJackson2Deserializer.java
@Override public OAuth2Exception deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken();// w w w. j a va 2 s . c om if (t == JsonToken.START_OBJECT) { t = jp.nextToken(); } Map<String, Object> errorParams = new HashMap<String, Object>(); for (; t == JsonToken.FIELD_NAME; t = jp.nextToken()) { // Must point to field name String fieldName = jp.getCurrentName(); // And then the value... t = jp.nextToken(); // Note: must handle null explicitly here; value deserializers won't Object value; if (t == JsonToken.VALUE_NULL) { value = null; } // Some servers might send back complex content else if (t == JsonToken.START_ARRAY) { value = jp.readValueAs(List.class); } else if (t == JsonToken.START_OBJECT) { value = jp.readValueAs(Map.class); } else { value = jp.getText(); } errorParams.put(fieldName, value); } Object errorCode = errorParams.get("error"); String errorMessage = errorParams.containsKey("error_description") ? errorParams.get("error_description").toString() : null; if (errorMessage == null) { errorMessage = errorCode == null ? "OAuth Error" : errorCode.toString(); } OAuth2Exception ex; if ("invalid_client".equals(errorCode)) { ex = new InvalidClientException(errorMessage); } else if ("unauthorized_client".equals(errorCode)) { ex = new UnauthorizedUserException(errorMessage); } else if ("invalid_grant".equals(errorCode)) { if (errorMessage.toLowerCase().contains("redirect") && errorMessage.toLowerCase().contains("match")) { ex = new RedirectMismatchException(errorMessage); } else { ex = new InvalidGrantException(errorMessage); } } else if ("invalid_scope".equals(errorCode)) { ex = new InvalidScopeException(errorMessage); } else if ("invalid_token".equals(errorCode)) { ex = new InvalidTokenException(errorMessage); } else if ("invalid_request".equals(errorCode)) { ex = new InvalidRequestException(errorMessage); } else if ("redirect_uri_mismatch".equals(errorCode)) { ex = new RedirectMismatchException(errorMessage); } else if ("unsupported_grant_type".equals(errorCode)) { ex = new UnsupportedGrantTypeException(errorMessage); } else if ("unsupported_response_type".equals(errorCode)) { ex = new UnsupportedResponseTypeException(errorMessage); } else if ("insufficient_scope".equals(errorCode)) { ex = new InsufficientScopeException(errorMessage, OAuth2Utils.parseParameterList((String) errorParams.get("scope"))); } else if ("access_denied".equals(errorCode)) { ex = new UserDeniedAuthorizationException(errorMessage); } else { ex = new OAuth2Exception(errorMessage); } Set<Map.Entry<String, Object>> entries = errorParams.entrySet(); for (Map.Entry<String, Object> entry : entries) { String key = entry.getKey(); if (!"error".equals(key) && !"error_description".equals(key)) { Object value = entry.getValue(); ex.addAdditionalInformation(key, value == null ? null : value.toString()); } } return ex; }
From source file:org.dbrain.data.jackson.serializers.JacksonSerializationUtils.java
public static Value parseValue(JsonParser parser, DeserializationContext ctxt) throws IOException { JsonToken token = getToken(parser);//from w w w . j av a2 s . c o m if (token != null) { Value result; switch (token) { case VALUE_STRING: result = Value.of(parser.getValueAsString()); break; case VALUE_NUMBER_FLOAT: result = Value.of(parser.getDoubleValue()); break; case VALUE_NUMBER_INT: result = Value.of(parser.getBigIntegerValue()); break; case VALUE_NULL: result = NullValueImpl.NULL; break; case VALUE_TRUE: result = Value.of(Boolean.TRUE); break; case VALUE_FALSE: result = Value.of(Boolean.FALSE); break; case START_OBJECT: { ValueMap values = ValueMap.newInstance(); while (parser.nextToken() == JsonToken.FIELD_NAME) { String key = parser.getCurrentName(); parser.nextToken(); Value v = parseValue(parser, ctxt); if (v == null) { throw ctxt.wrongTokenException(parser, JsonToken.START_OBJECT, "Expected Value"); } values.put(key, v); } if (getToken(parser) == JsonToken.END_OBJECT) { parser.clearCurrentToken(); } else { throw ctxt.wrongTokenException(parser, JsonToken.END_OBJECT, null); } result = values; } break; case START_ARRAY: { ValueList values = ValueList.newInstance(); while (parser.nextToken() != JsonToken.END_ARRAY) { Value v = parseValue(parser, ctxt); if (v == null) { throw ctxt.wrongTokenException(parser, JsonToken.START_OBJECT, "Expected Value"); } values.add(v); } if (getToken(parser) == JsonToken.END_ARRAY) { parser.clearCurrentToken(); } else { throw ctxt.wrongTokenException(parser, JsonToken.END_ARRAY, null); } result = values; } break; default: throw ctxt.wrongTokenException(parser, JsonToken.START_OBJECT, "Expected Value"); } return result; } else { return null; } }
From source file:org.apache.metamodel.json.JsonDocumentSource.java
public Document next() { while (true) { final JsonToken token = getNextToken(); if (token == null) { return null; }/*from ww w. j a v a2s. co m*/ if (token == JsonToken.START_OBJECT) { Map<String, ?> value = readValue(); return new Document(_sourceCollectionName, value, value); } } }
From source file:com.microsoft.azure.storage.core.JsonUtilities.java
/*** * Reserved for internal use. Asserts that the current token of the parser is the start of an object. * /*from w w w. j a va 2 s . c o m*/ * @param parser * The {@link JsonParser} whose current token to check. */ public 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:com.taveloper.http.test.StreamParseUtil.java
/** * Starts parsing an object or array by making sure the parser points to an * object field name, first array value or end of object or array. <p> If * the parser is at the start of input, {@link #nextToken()} is called. The * current token must then be {@link JsonToken#START_OBJECT}, {@link JsonToken#END_OBJECT}, * {@link JsonToken#START_ARRAY}, {@link JsonToken#END_ARRAY}, or * {@link JsonToken#FIELD_NAME}. For an object only, after the method is * called, the current token must be either {@link JsonToken#FIELD_NAME} or * {@link JsonToken#END_OBJECT}. </p> *///from www . ja va2 s. co m public static JsonToken startParsingObject(JsonParser parser) throws IOException { JsonToken currentToken = startParsing(parser); if (currentToken != JsonToken.START_OBJECT) { currentToken = nextToken(parser); } // Preconditions.checkArgument(currentToken == JsonToken.START_OBJECT, currentToken + "is not a Json Object!"); currentToken = nextToken(parser); // Preconditions.checkArgument( // currentToken == JsonToken.FIELD_NAME || currentToken == JsonToken.END_OBJECT, // currentToken); return currentToken; }
From source file:io.seldon.spark.actions.JobUtils.java
public static ActionData getActionDataFromActionLogLine(String actionLogLine) { ActionData actionData = new ActionData(); String[] parts = actionLogLine.split("\\s+", 3); String json = parts[2];/* ww w . ja va 2 s . c o m*/ actionData.timestamp_utc = parts[0]; JsonFactory jsonF = new JsonFactory(); try { JsonParser jp = jsonF.createParser(json); if (jp.nextToken() != JsonToken.START_OBJECT) { throw new IOException("Expected data to start with an Object"); } while (jp.nextToken() != JsonToken.END_OBJECT) { String fieldName = jp.getCurrentName(); // Let's move to value jp.nextToken(); if (fieldName.equals("client")) { actionData.client = jp.getText(); } else if (fieldName.equals("client_userid")) { actionData.client_userid = jp.getText(); } else if (fieldName.equals("userid")) { actionData.userid = jp.getValueAsInt(); } else if (fieldName.equals("itemid")) { actionData.itemid = jp.getValueAsInt(); } else if (fieldName.equals("client_itemid")) { actionData.client_itemid = jp.getText(); } else if (fieldName.equals("rectag")) { actionData.rectag = jp.getText(); } else if (fieldName.equals("type")) { actionData.type = jp.getValueAsInt(); } else if (fieldName.equals("value")) { actionData.value = jp.getValueAsDouble(); } } jp.close(); } catch (JsonParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return actionData; }
From source file:com.amazonaws.hal.client.HalJsonArrayUnmarshaller.java
@Override public List<T> unmarshall(JsonUnmarshallerContext context) throws Exception { List<T> list = new ArrayList<>(); JsonToken token = context.getCurrentToken(); while (token != null && token != END_ARRAY) { if (token == JsonToken.START_OBJECT) { list.add(itemUnmarshaller.unmarshall(context)); }/*from w ww . jav a2s .com*/ token = context.nextToken(); } return list; }
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 2s . c o m * @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:com.joliciel.jochre.search.webClient.SearchResults.java
public SearchResults(String json) { try {//from w w w . j av a 2 s . c o m scoreDocs = new ArrayList<SearchDocument>(); Reader reader = new StringReader(json); JsonFactory jsonFactory = new JsonFactory(); // or, for data binding, org.codehaus.jackson.mapper.MappingJsonFactory JsonParser jsonParser = jsonFactory.createJsonParser(reader); // Sanity check: verify that we got "Json Object": if (jsonParser.nextToken() != JsonToken.START_OBJECT) throw new RuntimeException("Expected START_OBJECT, but was " + jsonParser.getCurrentToken() + " at " + jsonParser.getCurrentLocation()); while (jsonParser.nextToken() != JsonToken.END_OBJECT) { String baseName = jsonParser.getCurrentName(); LOG.debug("Found baseName: " + baseName); if (jsonParser.nextToken() != JsonToken.START_OBJECT) throw new RuntimeException("Expected START_OBJECT, but was " + jsonParser.getCurrentToken() + " at " + jsonParser.getCurrentLocation()); SearchDocument doc = new SearchDocument(baseName, jsonParser); scoreDocs.add(doc); } // next scoreDoc } catch (JsonParseException e) { LOG.error(e); throw new RuntimeException(e); } catch (IOException e) { LOG.error(e); throw new RuntimeException(e); } }