List of usage examples for com.fasterxml.jackson.core JsonToken END_OBJECT
JsonToken END_OBJECT
To view the source code for com.fasterxml.jackson.core JsonToken END_OBJECT.
Click Source Link
From source file:com.adobe.communities.ugc.migration.importer.MessagesImportServlet.java
private void importMessages(final SlingHttpServletRequest request, final JsonParser jsonParser, final Map<String, Object> messageModifiers) throws ServletException { if (!jsonParser.getCurrentToken().equals(JsonToken.START_ARRAY)) { throw new ServletException("unexpected starting token " + jsonParser.getCurrentToken().asString()); }//from ww w. j a v a 2s.c om try { jsonParser.nextToken(); //presumably, we will advance to a "start object" token while (!jsonParser.getCurrentToken().equals(JsonToken.END_ARRAY)) { final Map<String, Map<String, Boolean>> recipientModifiers = new HashMap<String, Map<String, Boolean>>(); final Map<String, Object> props = new HashMap<String, Object>(); final Map<String, Object> messageModifier = new HashMap<String, Object>(); List<FileDataSource> attachments = new ArrayList<FileDataSource>(); String sender = ""; jsonParser.nextToken(); //field name while (!jsonParser.getCurrentToken().equals(JsonToken.END_OBJECT)) { final String fieldName = jsonParser.getCurrentName(); jsonParser.nextToken(); //value if (fieldName.equals("senderId")) { sender = URLDecoder.decode(jsonParser.getValueAsString(), "UTF-8"); } else if (fieldName.equals("added")) { final Calendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(jsonParser.getLongValue()); messageModifier.put("added", calendar); } else if (fieldName.equals("recipients")) { // build the string for the "to" property and also create the modifiers we'll need later final StringBuilder recipientString = new StringBuilder(); //iterate over each key (each being a recipient id) if (jsonParser.getCurrentToken().equals(JsonToken.START_OBJECT)) { jsonParser.nextToken(); // should get first recipientId while (!jsonParser.getCurrentToken().equals(JsonToken.END_OBJECT)) { final String recipientId = jsonParser.getCurrentName(); jsonParser.nextToken(); //start object jsonParser.nextToken(); //first label final Map<String, Boolean> interactionModifiers = new HashMap<String, Boolean>(); while (!jsonParser.getCurrentToken().equals(JsonToken.END_OBJECT)) { final String label = jsonParser.getCurrentName(); jsonParser.nextToken(); final Boolean labelValue = jsonParser.getBooleanValue(); interactionModifiers.put(label, labelValue); jsonParser.nextToken(); //next label or end object } try { final String userPath = userPropertiesService.getAuthorizablePath(recipientId); recipientModifiers.put(userPath, interactionModifiers); recipientString.append(recipientId); } catch (final RepositoryException e) { // log the fact that a recipient specified in the json file doesn't exist in this // environment throw new ServletException( "A recipient specified in the migration file couldn't " + "be found in this environment", e); } jsonParser.nextToken(); // next recipientId or end object if (jsonParser.getCurrentToken().equals(JsonToken.FIELD_NAME)) { recipientString.append(';'); } } props.put("to", recipientString); messageModifier.put("recipientDetails", recipientModifiers); } } else if (fieldName.equals(ContentTypeDefinitions.LABEL_ATTACHMENTS)) { UGCImportHelper.getAttachments(jsonParser, attachments); } else { props.put(fieldName, URLDecoder.decode(jsonParser.getValueAsString(), "UTF-8")); } jsonParser.nextToken(); //either next field name or end object } final Random range = new Random(); final String key = String.valueOf(range.nextInt(Integer.MAX_VALUE)) + String.valueOf(range.nextInt(Integer.MAX_VALUE)); // we're going to temporarily overwrite the subject (to do a search) and need to track its initial value if (props.containsKey("subject")) { messageModifier.put("subject", props.get("subject")); } else { messageModifier.put("subject", ""); } props.put("subject", key); //use subject as the search key messageModifiers.put(key, messageModifier); try { short result = messagingService.create(request.getResourceResolver(), request.getResource(), sender, props, attachments, clientUtilsFactory.getClientUtilities(xss, request, socialUtils)); if (result != 200) { throw new ServletException("Message sending failed. Return code was " + result); } } catch (final OperationException e) { throw new ServletException("Unable to create a message through the operation service", e); } jsonParser.nextToken(); //either END_ARRAY or START_OBJECT } } catch (final IOException e) { throw new ServletException("Encountered exception while parsing json content", e); } }
From source file:io.apiman.manager.api.exportimport.json.JsonImportReader.java
public void readClients() throws Exception { current = nextToken();/* w w w .j ava 2 s .c om*/ if (current == JsonToken.END_ARRAY) { return; } while (nextToken() != JsonToken.END_ARRAY) { // Traverse each api definition while (nextToken() != JsonToken.END_OBJECT) { if (jp.getCurrentName().equals(ClientBean.class.getSimpleName())) { current = nextToken(); ClientBean apiBean = jp.readValueAs(ClientBean.class); dispatcher.client(apiBean); } else { OrgElementsEnum fieldName = OrgElementsEnum.valueOf(jp.getCurrentName()); current = nextToken(); switch (fieldName) { case Versions: readClientVersions(); break; default: throw new RuntimeException("Unhandled entity " + fieldName + " with token " + current); } } } } }
From source file:com.unboundid.scim2.client.requests.SearchRequestBuilder.java
/** * Invoke the SCIM retrieve request./*from ww w .ja v a 2s . c o m*/ * * @param post {@code true} to send the request using POST or {@code false} * to send the request using GET. * @param <T> The type of objects to return. * @param resultHandler The search result handler that should be used to * process the resources. * @param cls The Java class object used to determine the type to return. * @throws ScimException If an error occurred. */ private <T> void invoke(final boolean post, final SearchResultHandler<T> resultHandler, final Class<T> cls) throws ScimException { Response response; if (post) { Set<String> attributeSet = null; Set<String> excludedAttributeSet = null; if (attributes != null && attributes.size() > 0) { if (!excluded) { attributeSet = attributes; } else { excludedAttributeSet = attributes; } } SearchRequest searchRequest = new SearchRequest(attributeSet, excludedAttributeSet, filter, sortBy, sortOrder, startIndex, count); Invocation.Builder builder = target().path(ApiConstants.SEARCH_WITH_POST_PATH_EXTENSION) .request(ScimService.MEDIA_TYPE_SCIM_TYPE, MediaType.APPLICATION_JSON_TYPE); for (Map.Entry<String, List<Object>> header : headers.entrySet()) { builder = builder.header(header.getKey(), StaticUtils.listToString(header.getValue(), ", ")); } response = builder.post(Entity.entity(searchRequest, getContentType())); } else { response = buildRequest().get(); } try { if (response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) { InputStream inputStream = response.readEntity(InputStream.class); try { JsonParser parser = JsonUtils.getObjectReader().getFactory().createParser(inputStream); try { parser.nextToken(); boolean stop = false; while (!stop && parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if (field.equals("schemas")) { parser.skipChildren(); } else if (field.equals("totalResults")) { resultHandler.totalResults(parser.getIntValue()); } else if (field.equals("startIndex")) { resultHandler.startIndex(parser.getIntValue()); } else if (field.equals("itemsPerPage")) { resultHandler.itemsPerPage(parser.getIntValue()); } else if (field.equals("Resources")) { while (parser.nextToken() != JsonToken.END_ARRAY) { if (!resultHandler.resource(parser.readValueAs(cls))) { stop = true; break; } } } else if (SchemaUtils.isUrn(field)) { resultHandler.extension(field, parser.<ObjectNode>readValueAsTree()); } else { // Just skip this field parser.nextToken(); } } } finally { if (inputStream != null) { inputStream.close(); } parser.close(); } } catch (IOException e) { throw new ResponseProcessingException(response, e); } } else { throw toScimException(response); } } finally { response.close(); } }
From source file:org.oscim.utils.overpass.OverpassAPIReader.java
private void parseRelation(JsonParser jp) throws JsonParseException, IOException { long id = 0;//from w w w. j av a2s .c om TagSet tags = null; ArrayList<TmpRelation> members = new ArrayList<TmpRelation>(); while (jp.nextToken() != JsonToken.END_OBJECT) { String name = jp.getCurrentName(); jp.nextToken(); if ("id".equals(name)) id = jp.getLongValue(); else if ("members".equals(name)) { while (jp.nextToken() != JsonToken.END_ARRAY) { TmpRelation member = new TmpRelation(); while (jp.nextToken() != JsonToken.END_OBJECT) { name = jp.getCurrentName(); jp.nextToken(); if ("type".equals(name)) member.type = jp.getText(); else if ("ref".equals(name)) member.id = Long.valueOf(jp.getLongValue()); else if ("role".equals(name)) member.role = jp.getText(); } members.add(member); } } else if ("tags".equals(name)) tags = parseTags(jp); } OsmRelation relation = new OsmRelation(tags, id, members.size()); ownRelations.add(relation); relationsById.put(Long.valueOf(id), relation); relationMembersForRelation.put(relation, members); }
From source file:com.adobe.communities.ugc.migration.importer.UGCImportHelper.java
public static void extractTally(final Resource post, final JsonParser jsonParser, final ModifyingResourceProvider srp, final TallyOperationsService tallyOperationsService) throws IOException { jsonParser.nextToken(); // should be start object, but would be end array if no objects were present while (!jsonParser.getCurrentToken().equals(JsonToken.END_ARRAY)) { Long timestamp = null;// www.j a v a 2s .c o m String userIdentifier = null; String response = null; String tallyType = null; jsonParser.nextToken(); // should make current token by "FIELD_NAME" but could be END_OBJECT if this were // an empty object while (!jsonParser.getCurrentToken().equals(JsonToken.END_OBJECT)) { final String label = jsonParser.getCurrentName(); jsonParser.nextToken(); // should be FIELD_VALUE if (label.equals(TallyConstants.TIMESTAMP_PROPERTY)) { timestamp = jsonParser.getValueAsLong(); } else { final String responseValue = jsonParser.getValueAsString(); if (label.equals("response")) { response = URLDecoder.decode(responseValue, "UTF-8"); } else if (label.equals("userIdentifier")) { userIdentifier = URLDecoder.decode(responseValue, "UTF-8"); } else if (label.equals("tallyType")) { tallyType = responseValue; } } jsonParser.nextToken(); // should make current token be "FIELD_NAME" unless we're at the end of our // loop and it's now "END_OBJECT" instead } if (timestamp != null && userIdentifier != null && response != null && tallyType != null) { createTally(srp, post, tallyType, userIdentifier, timestamp, response, tallyOperationsService); } jsonParser.nextToken(); // may advance to "START_OBJECT" if we're not finished yet, but might be // "END_ARRAY" now } }
From source file:com.amazonaws.services.cloudtrail.processinglibrary.serializer.AbstractEventSerializer.java
/** * Parse user identity in CloudTrailEventData * * @param eventData/* w w w. ja v a 2 s . c o m*/ * @throws IOException */ private void parseUserIdentity(CloudTrailEventData eventData) throws IOException { JsonToken nextToken = this.jsonParser.nextToken(); if (nextToken == JsonToken.VALUE_NULL) { eventData.add(CloudTrailEventField.userIdentity.name(), null); return; } if (nextToken != JsonToken.START_OBJECT) { throw new JsonParseException("Not a UserIdentity object", this.jsonParser.getCurrentLocation()); } UserIdentity userIdentity = new UserIdentity(); while (this.jsonParser.nextToken() != JsonToken.END_OBJECT) { String key = this.jsonParser.getCurrentName(); switch (key) { case "type": userIdentity.add(CloudTrailEventField.type.name(), this.jsonParser.nextTextValue()); break; case "principalId": userIdentity.add(CloudTrailEventField.principalId.name(), this.jsonParser.nextTextValue()); break; case "arn": userIdentity.add(CloudTrailEventField.arn.name(), this.jsonParser.nextTextValue()); break; case "accountId": userIdentity.add(CloudTrailEventField.accountId.name(), this.jsonParser.nextTextValue()); break; case "accessKeyId": userIdentity.add(CloudTrailEventField.accessKeyId.name(), this.jsonParser.nextTextValue()); break; case "userName": userIdentity.add(CloudTrailEventField.userName.name(), this.jsonParser.nextTextValue()); break; case "sessionContext": this.parseSessionContext(userIdentity); break; case "invokedBy": userIdentity.add(CloudTrailEventField.invokedBy.name(), this.jsonParser.nextTextValue()); break; default: userIdentity.add(key, this.parseDefaultValue(key)); break; } } eventData.add(CloudTrailEventField.userIdentity.name(), userIdentity); }
From source file:com.github.shyiko.jackson.module.advice.AdvisedBeanDeserializer.java
/** * Streamlined version that is only used when no "special" * features are enabled.//from w ww.jav a 2 s . c o m */ private Object vanillaDeserialize(JsonParser jp, DeserializationContext ctxt, JsonToken t) throws IOException { final Object bean = _valueInstantiator.createUsingDefault(ctxt); beanDeserializerAdvice.before(bean, jp, ctxt); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { String propName = jp.getCurrentName(); // Skip field name: jp.nextToken(); if (beanDeserializerAdvice.intercept(bean, propName, jp, ctxt)) { continue; } SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { // normal case try { prop.deserializeAndSet(jp, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); } } else { handleUnknownVanilla(jp, ctxt, bean, propName); } } beanDeserializerAdvice.after(bean, jp, ctxt); return bean; }
From source file:com.quinsoft.zeidon.standardoe.ActivateOisFromJsonStream.java
private boolean readOi() throws Exception { JsonToken token = jp.nextToken();/*w w w. j a v a2 s. c o m*/ // If we find the end of the OI array then that's the end of OIs. if (token == JsonToken.END_ARRAY) return false; // No more OIs in the stream. if (token != JsonToken.START_OBJECT) throw new ZeidonException("OI JSON stream doesn't start with object."); token = jp.nextToken(); String fieldName = jp.getCurrentName(); if (StringUtils.equals(fieldName, ".oimeta")) token = readOiMeta(); else throw new ZeidonException(".oimeta object not specified in JSON stream"); // If the token after reading the .oimeta is END_OBJECT then the OI is empty. if (token != JsonToken.END_OBJECT) { fieldName = jp.getCurrentName(); if (!StringUtils.equalsIgnoreCase(fieldName, lodDef.getRoot().getName())) throw new ZeidonException("First entity specified in OI (%s) is not the root (%s)", fieldName, lodDef.getRoot().getName()); readEntity(fieldName); token = jp.nextToken(); } if (selectedInstances.size() > 0) setCursors(); else view.reset(); if (token != JsonToken.END_OBJECT) throw new ZeidonException("OI JSON stream doesn't end with object."); if (readOnlyOi) ((InternalView) view).getViewImpl().getObjectInstance().setReadOnly(true); if (readOnly) view.setReadOnly(true); if (totalRootCount != null) view.setTotalRootCount(totalRootCount); return true; // Keep looking for OIs in the stream. }
From source file:org.oscim.utils.overpass.OverpassAPIReader.java
private static TagSet parseTags(JsonParser jp) throws JsonParseException, IOException { TagSet tags = null;//from ww w. j av a 2s .co m while (jp.nextToken() != JsonToken.END_OBJECT) { String key = jp.getCurrentName(); jp.nextToken(); String val = jp.getText(); if (tags == null) tags = new TagSet(4); tags.add(new Tag(key, val, false)); } return tags; }
From source file:com.netflix.hollow.jsonadapter.discover.HollowJsonAdapterSchemaDiscoverer.java
private void discoverSubMapSchemas(JsonParser parser, HollowDiscoveredSchema objectSchema) throws IOException { JsonToken token = parser.nextToken(); if (isDebug)// ww w .j a v a2 s . c o m System.out.println( "discoverSubMapSchemas[START]: token=" + token + ", fieldname=" + parser.getCurrentName()); while (token != JsonToken.END_OBJECT) { if (isDebug) System.out.println( "discoverSubMapSchemas[LOOP]: token=" + token + ", fieldname=" + parser.getCurrentName()); if (token != JsonToken.FIELD_NAME) { if (token == JsonToken.START_OBJECT) { if (isDebug) System.out.println("discoverSubMapSchemas[LOOP] discoverSchemas: token=" + token + ", fieldname=" + parser.getCurrentName()); discoverSchemas(parser, objectSchema); } else { if (isDebug) System.out.println("discoverSubMapSchemas[LOOP] discoverSchemaField: token=" + token + ", fieldname=" + parser.getCurrentName()); discoverSchemaField(parser, token, "value", objectSchema); } } token = parser.nextToken(); } if (isDebug) System.out.println("discoverSubMapSchemas[END]: token=" + token); }