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.tage.calcite.adapter.druid.DruidConnectionImpl.java
private void expectObjectField(JsonParser parser, String name) throws IOException { expect(parser, JsonToken.FIELD_NAME); if (!parser.getCurrentName().equals(name)) { throw new RuntimeException("expected field " + name + ", got " + parser.getCurrentName()); }// w w w .j a v a 2s . c o m expect(parser, JsonToken.START_OBJECT); while (parser.nextToken() != JsonToken.END_OBJECT) { // empty } }
From source file:com.concentricsky.android.khanacademy.data.remote.LibraryUpdaterTask.java
private ChildArrayResults parseChildArray(JsonParser parser, SQLiteDatabase tempDb, String parentTopic_id) throws JsonParseException, IOException { ChildArrayResults result = new ChildArrayResults(); int seq = 0;//from w w w.j a v a2 s .c om JsonToken currentToken = parser.getCurrentToken(); if (currentToken == JsonToken.START_ARRAY) { while (parser.nextValue() == JsonToken.START_OBJECT) { // Otherwise, we will be at END_ARRAY here. ContentValues values = parseObject(parser, tempDb, parentTopic_id, seq++); if (values != null && values.containsKey("kind")) { String kind = values.getAsString("kind"); if ("Topic".equals(kind) && values.containsKey("_id")) { result.childKind = kind; result.childIds.add(values.getAsString("_id")); result.videoCount += values.getAsInteger("video_count"); if (result.thumbId == null && values.containsKey("thumb_id")) { // Return the first available thumb id as this topic's thumb id. result.thumbId = values.getAsString("thumb_id"); } } else if ("Video".equals(kind) && values.containsKey("readable_id")) { result.childKind = kind; result.childIds.add(values.getAsString("readable_id")); result.videoCount += 1; if (result.thumbId == null && values.containsKey("pngurl")) { // Return youtube_id of first video with a thumbnail as this topic's thumbnail id. result.thumbId = values.getAsString("youtube_id"); } } } } } return result; }
From source file:org.wso2.extension.siddhi.map.json.sourcemapper.JsonSourceMapper.java
private Event convertToSingleEventForDefaultMapping(Object eventObject) throws IOException { Event event = new Event(attributesSize); Object[] data = event.getData(); JsonParser parser;//from w w w . j a v a 2s . c o m int numberOfProvidedAttributes = 0; try { parser = factory.createParser(eventObject.toString()); } catch (IOException e) { throw new SiddhiAppRuntimeException( "Initializing a parser failed for the event string." + eventObject.toString()); } int position; while (!parser.isClosed()) { JsonToken jsonToken = parser.nextToken(); if (JsonToken.START_OBJECT.equals(jsonToken)) { parser.nextToken(); if (DEFAULT_JSON_EVENT_IDENTIFIER.equalsIgnoreCase(parser.getText())) { parser.nextToken(); } else { log.error("Default json message " + eventObject + " contains an invalid event identifier. Required \"event\", " + "but found \"" + parser.getText() + "\". Hence dropping the message."); return null; } } else if (JsonToken.FIELD_NAME.equals(jsonToken)) { String key = parser.getCurrentName(); numberOfProvidedAttributes++; position = findDefaultMappingPosition(key); if (position == -1) { log.error("Stream \"" + streamDefinition.getId() + "\" does not have an attribute named \"" + key + "\", but the received event " + eventObject.toString() + " does. Hence dropping the message."); return null; } jsonToken = parser.nextToken(); Attribute.Type type = streamAttributes.get(position).getType(); if (JsonToken.VALUE_NULL.equals(jsonToken)) { data[position] = null; } else { switch (type) { case BOOL: if (JsonToken.VALUE_TRUE.equals(jsonToken) || JsonToken.VALUE_FALSE.equals(jsonToken)) { data[position] = parser.getValueAsBoolean(); } else { log.error("Json message " + eventObject.toString() + " contains incompatible attribute types and values. Value " + parser.getText() + " is not compatible with type BOOL. " + "Hence dropping the message."); return null; } break; case INT: if (JsonToken.VALUE_NUMBER_INT.equals(jsonToken)) { data[position] = parser.getValueAsInt(); } else { log.error("Json message " + eventObject.toString() + " contains incompatible attribute types and values. Value " + parser.getText() + " is not compatible with type INT. " + "Hence dropping the message."); return null; } break; case DOUBLE: if (JsonToken.VALUE_NUMBER_FLOAT.equals(jsonToken)) { data[position] = parser.getValueAsDouble(); } else { log.error("Json message " + eventObject.toString() + " contains incompatible attribute types and values. Value " + parser.getText() + " is not compatible with type DOUBLE. " + "Hence dropping the message."); return null; } break; case STRING: if (JsonToken.VALUE_STRING.equals(jsonToken)) { data[position] = parser.getValueAsString(); } else { log.error("Json message " + eventObject.toString() + " contains incompatible attribute types and values. Value " + parser.getText() + " is not compatible with type STRING. " + "Hence dropping the message."); return null; } break; case FLOAT: if (JsonToken.VALUE_NUMBER_FLOAT.equals(jsonToken) || JsonToken.VALUE_NUMBER_INT.equals(jsonToken)) { data[position] = attributeConverter.getPropertyValue(parser.getValueAsString(), Attribute.Type.FLOAT); } else { log.error("Json message " + eventObject.toString() + " contains incompatible attribute types and values. Value " + parser.getText() + " is not compatible with type FLOAT. " + "Hence dropping the message."); return null; } break; case LONG: if (JsonToken.VALUE_NUMBER_INT.equals(jsonToken)) { data[position] = parser.getValueAsLong(); } else { log.error("Json message " + eventObject.toString() + " contains incompatible attribute types and values. Value " + parser.getText() + " is not compatible with type LONG. " + "Hence dropping the message."); return null; } break; default: return null; } } } } if (failOnMissingAttribute && (numberOfProvidedAttributes != attributesSize)) { log.error("Json message " + eventObject.toString() + " contains missing attributes. Hence dropping the message."); return null; } return event; }
From source file:com.quinsoft.zeidon.standardoe.ActivateOisFromJsonStream.java
private void readEntity(String entityName) throws Exception { // Keeps track of whether the entity list starts with a [ or not. If there // is no [ then we are done reading entities of this type when we find the // end of the object. boolean entityArray = false; int twinCount = 0; JsonToken token = jp.getCurrentToken(); if (token == JsonToken.START_ARRAY) { token = jp.nextToken();//w w w . j ava 2 s. co m entityArray = true; // Entity list started with [ } assert token == JsonToken.START_OBJECT; EntityDef entityDef = lodDef.getEntityDef(entityName, true, true); // Read tokens until we find the token that ends the current list of entities. while ((token = jp.nextToken()) != null) { twinCount++; if (token == JsonToken.END_ARRAY) break; if (token == JsonToken.END_OBJECT) { // If we get here then this should indicate an empty OI. Get the next // token, verify that it's an END_ARRAY, and return. token = jp.nextToken(); assert token == JsonToken.END_ARRAY; break; } // If there are multiple twins then the token is START_OBJECT to // indicate a new EI. if (token == JsonToken.START_OBJECT) { assert twinCount > 1; // Assert that we already created at least one EI. token = jp.nextToken(); } assert token == JsonToken.FIELD_NAME; EntityInstanceImpl ei = (EntityInstanceImpl) view.cursor(entityDef).createEntity(CursorPosition.LAST, CREATE_FLAGS); List<AttributeMeta> attributeMetas = new ArrayList<>(); // Read tokens until we find the token that ends the current entity. EntityMeta entityMeta = DEFAULT_ENTITY_META; while ((token = jp.nextToken()) != JsonToken.END_OBJECT) { String fieldName = jp.getCurrentName(); if (token == JsonToken.FIELD_NAME || token == JsonToken.START_OBJECT) token = jp.nextToken(); if (StringUtils.equals(fieldName, ".meta")) { entityMeta = readEntityMeta(ei); // Now that we have everything we can perform some processing. if (entityMeta.isLinkedSource) linkSources.put(entityMeta.entityKey, ei); else if (entityMeta.linkedSource != null) ei.linkInstances(linkSources.get(entityMeta.linkedSource)); continue; } if (fieldName.startsWith(".")) { AttributeMeta am = readAttributeMeta(ei, fieldName); attributeMetas.add(am); continue; } // Is this the start of an entity. if (token == JsonToken.START_ARRAY || token == JsonToken.START_OBJECT) { boolean recursiveChild = false; // Validate that the entity name is valid. EntityDef childEntity = lodDef.getEntityDef(fieldName, true, true); if (childEntity.getParent() != entityDef) { // Check to see the childEntity is a recursive child. if (entityDef.isRecursive()) { view.cursor(entityDef).setToSubobject(); recursiveChild = true; } else throw new ZeidonException("Parse error: %s is not a child of %s", fieldName, entityName); } readEntity(fieldName); if (recursiveChild) view.resetSubobject(); continue; } if (StringUtils.equals(jp.getText(), fieldName)) // If jp points to attr name, get next token. token = jp.nextToken(); // This better be an attribute // Try getting the attribute. We won't throw an exception (yet) if there // is no attribute with a matching name. AttributeDef attributeDef = entityDef.getAttribute(fieldName, false, true); if (attributeDef == null) { // We didn't find an attribute with a name matching fieldName. Do we allow // dynamic attributes for this entity? if (options.getAllowableDynamicEntities() == null || !options.getAllowableDynamicEntities().contains(entityDef.getName())) { entityDef.getAttribute(fieldName); // This will throw the exception. } // We are allowing dynamic attributes. Create one. DynamicAttributeDefConfiguration config = new DynamicAttributeDefConfiguration(); config.setAttributeName(fieldName); attributeDef = entityDef.createDynamicAttributeDef(config); } else if (attributeDef.isDerived()) // We'll ignore derived attributes. continue; Domain domain = attributeDef.getDomain(); Object internalValue = domain.convertExternalValue(task, ei.getAttribute(attributeDef), attributeDef, null, jp.getText()); ei.getAttribute(attributeDef).setInternalValue(internalValue, !attributeDef.isKey()); if (incremental) { // Since incremental flags are set, assume the attribute hasn't been // updated. We'll be told later if it has. AttributeValue attrib = ei.getInternalAttribute(attributeDef); attrib.setUpdated(false); } else { // If we just set the key then we'll assume the entity has // already been created. if (attributeDef.isKey()) ei.setIncrementalFlags(IncrementalEntityFlags.UPDATED); } } // while ( ( token = jp.nextToken() ) != JsonToken.END_OBJECT )... // Apply all the attribute metas to correctly set the attribute flags. for (AttributeMeta am : attributeMetas) am.apply(ei); // Now that we've updated everything, set the flags. if (incremental) { ei.setCreated(entityMeta.created); ei.setUpdated(entityMeta.updated); ei.setDeleted(entityMeta.deleted); ei.setIncluded(entityMeta.included); ei.setExcluded(entityMeta.excluded); if (entityMeta.incomplete) ei.setIncomplete(null); if (entityMeta.lazyLoaded != null) { String[] names = entityMeta.lazyLoaded.split(","); for (String name : names) ei.getEntitiesLoadedLazily().add(lodDef.getEntityDef(name, true, true)); } } // If the entity list didn't start with a [ then there is only one entity // in the list of twins so exit. if (entityArray == false) break; } // while ( ( token = jp.nextToken() ) != null )... }
From source file:com.amazonaws.services.cloudtrail.processinglibrary.serializer.AbstractEventSerializer.java
/** * Parse web identify session object//w ww. ja va2 s. c om * * @param sessionContext * @return the web identity session context * @throws IOException */ private WebIdentitySessionContext parseWebIdentitySessionContext(SessionContext sessionContext) throws IOException { if (this.jsonParser.nextToken() != JsonToken.START_OBJECT) { throw new JsonParseException("Not a WebIdentitySessionContext object", this.jsonParser.getCurrentLocation()); } WebIdentitySessionContext webIdFederationData = new WebIdentitySessionContext(); while (this.jsonParser.nextToken() != JsonToken.END_OBJECT) { String key = this.jsonParser.getCurrentName(); switch (key) { case "attributes": webIdFederationData.add(CloudTrailEventField.attributes.name(), this.parseAttributes()); break; case "federatedProvider": webIdFederationData.add(CloudTrailEventField.federatedProvider.name(), this.jsonParser.nextTextValue()); break; default: webIdFederationData.add(key, this.parseDefaultValue(key)); break; } } return webIdFederationData; }
From source file:org.helm.notation2.wsadapter.MonomerWSLoader.java
/** * Private routine to deserialize JSON containing monomer categorization data. * This is done manually to give more freedom regarding data returned by the * webservice.// w w w . j av a 2 s . c o m * * @param parser the JSONParser containing JSONData. * @return List containing the monomer categorization * * @throws JsonParseException * @throws IOException */ private static List<CategorizedMonomer> deserializeEditorCategorizationConfig(JsonParser parser) throws JsonParseException, IOException { List<CategorizedMonomer> config = new LinkedList<CategorizedMonomer>(); CategorizedMonomer currentMonomer = null; parser.nextToken(); while (parser.hasCurrentToken()) { String fieldName = parser.getCurrentName(); JsonToken token = parser.getCurrentToken(); if (JsonToken.START_OBJECT.equals(token)) { currentMonomer = new CategorizedMonomer(); } else if (JsonToken.END_OBJECT.equals(token)) { config.add(currentMonomer); } if (fieldName != null) { switch (fieldName) { // id is first field case "monomerID": parser.nextToken(); currentMonomer.setMonomerID(parser.getText()); break; case "monomerName": parser.nextToken(); currentMonomer.setMonomerName(parser.getText()); break; case "naturalAnalogon": parser.nextToken(); currentMonomer.setNaturalAnalogon(parser.getText()); break; case "monomerType": parser.nextToken(); currentMonomer.setMonomerType(parser.getText()); break; case "polymerType": parser.nextToken(); currentMonomer.setPolymerType(parser.getText()); break; case "category": parser.nextToken(); currentMonomer.setCategory(parser.getText()); break; case "shape": parser.nextToken(); currentMonomer.setShape(parser.getText()); break; case "fontColor": parser.nextToken(); currentMonomer.setFontColor(parser.getText()); break; case "backgroundColor": parser.nextToken(); currentMonomer.setBackgroundColor(parser.getText()); break; default: break; } } parser.nextToken(); } return config; }
From source file:com.cinnober.msgcodec.json.JsonCodec.java
@Override public Object decode(InputStream in) throws IOException { JsonFactory f = new JsonFactory(); JsonParser p = f.createParser(in);/*from w w w . j av a2s . c om*/ JsonToken token = p.nextToken(); if (token == JsonToken.VALUE_NULL) { return null; } else if (token != JsonToken.START_OBJECT) { throw new DecodeException("Expected {"); } return dynamicGroupHandler.readValue(p); }
From source file:com.concentricsky.android.khanacademy.data.remote.LibraryUpdaterTask.java
private void parseDownloadUrls(JsonParser parser, ContentValues result) throws JsonParseException, IOException { // parser points at begin object token right now if (parser.getCurrentToken() == JsonToken.START_OBJECT) { while (parser.nextValue() != JsonToken.END_OBJECT) { String fieldName = parser.getCurrentName(); if (downloadUrlFields.contains(fieldName)) { result.put(fieldName + "url", parser.getValueAsString()); }//www .ja va 2s. com } } // else we must not have any download urls (null, '', something like that.) }
From source file:com.amazonaws.services.cloudtrail.processinglibrary.serializer.AbstractEventSerializer.java
/** * Parse session issuer object. It only happened on role session and federated session. * * @param sessionContext/*w w w.j a v a2s . co m*/ * @return the session issuer object. * @throws IOException */ private SessionIssuer parseSessionIssuer(SessionContext sessionContext) throws IOException { if (this.jsonParser.nextToken() != JsonToken.START_OBJECT) { throw new JsonParseException("Not a SessionIssuer object", this.jsonParser.getCurrentLocation()); } SessionIssuer sessionIssuer = new SessionIssuer(); while (this.jsonParser.nextToken() != JsonToken.END_OBJECT) { String key = this.jsonParser.getCurrentName(); switch (key) { case "type": sessionIssuer.add(CloudTrailEventField.type.name(), this.jsonParser.nextTextValue()); break; case "principalId": sessionIssuer.add(CloudTrailEventField.principalId.name(), this.jsonParser.nextTextValue()); break; case "arn": sessionIssuer.add(CloudTrailEventField.arn.name(), this.jsonParser.nextTextValue()); break; case "accountId": sessionIssuer.add(CloudTrailEventField.accountId.name(), this.jsonParser.nextTextValue()); break; case "userName": sessionIssuer.add(CloudTrailEventField.userName.name(), this.jsonParser.nextTextValue()); break; default: sessionIssuer.add(key, this.parseDefaultValue(key)); break; } } return sessionIssuer; }
From source file:org.apache.lucene.server.handlers.AddDocumentHandler.java
/** Parses the fields, which should look like {field1: * ..., field2: ..., ...} *///from w ww . jav a2 s.com public static void parseFields(IndexState state, Document doc, JsonParser p) throws IOException { JsonToken token = p.nextToken(); if (token != JsonToken.START_OBJECT) { throw new IllegalArgumentException("fields should be an object"); } while (true) { token = p.nextToken(); if (token == JsonToken.END_OBJECT) { break; } assert token == JsonToken.FIELD_NAME; parseOneField(p, state, doc, p.getText()); } }