List of usage examples for com.fasterxml.jackson.core JsonToken FIELD_NAME
JsonToken FIELD_NAME
To view the source code for com.fasterxml.jackson.core JsonToken FIELD_NAME.
Click Source Link
From source file:com.tage.calcite.adapter.druid.DruidConnectionImpl.java
private void parseFields(List<String> fieldNames, List<Primitive> fieldTypes, Row.RowBuilder rowBuilder, JsonParser parser) throws IOException { while (parser.nextToken() == JsonToken.FIELD_NAME) { parseField(fieldNames, fieldTypes, rowBuilder, parser); }//from www .ja v a 2 s . c o m }
From source file:org.ojai.json.impl.JsonStreamDocumentReader.java
@Override public EventType next() { isExtended = false;/*from www . j ava 2 s. c o m*/ if (eor()) { return null; } JsonToken currentToken = nextToken(); if (currentToken == JsonToken.FIELD_NAME) { fieldName = getCurrentName(); currentToken = nextToken(); } updateCurrentContainer(); switch (currentToken) { case START_OBJECT: setCurrentEventType(parseMap()); if (currentEvent == EventType.START_MAP) { containerStack.push(new ContainerContext(Type.MAP, fieldName)); } break; case END_OBJECT: setCurrentEventType(EventType.END_MAP); ContainerContext lastContainer = containerStack.pop(); if (lastContainer.getType() == Type.MAP) { fieldName = lastContainer.getFieldName(); } updateCurrentContainer(); break; case START_ARRAY: setCurrentEventType(EventType.START_ARRAY); if (!inMap()) { currentContainer.incrementIndex(); } containerStack.push(new ContainerContext(Type.ARRAY)); break; case END_ARRAY: setCurrentEventType(EventType.END_ARRAY); containerStack.pop(); updateCurrentContainer(); break; case VALUE_NULL: setCurrentEventType(EventType.NULL).cacheCurrentValue(); break; case VALUE_TRUE: case VALUE_FALSE: setCurrentEventType(EventType.BOOLEAN).cacheCurrentValue(); break; case VALUE_STRING: setCurrentEventType(EventType.STRING).cacheCurrentValue(); break; case VALUE_NUMBER_INT: case VALUE_NUMBER_FLOAT: setCurrentEventType(EventType.DOUBLE).cacheCurrentValue(); break; default: throw new DecodingException("Encountered unexpected token of type: " + currentToken); } if (!inMap() && currentEvent != EventType.END_MAP && currentEvent != EventType.START_ARRAY && currentEvent != EventType.END_ARRAY) { // if traversing an array, increment the index currentContainer.incrementIndex(); } if (currentEvent == EventType.START_MAP) { mapLevel++; } else if (currentEvent == EventType.END_MAP) { mapLevel--; } if (mapLevel == 0) { eor = true; } return currentEvent; }
From source file:eu.project.ttc.readers.TermSuiteJsonCasDeserializer.java
private static void fillWordAnnotations(JsonParser parser, JsonToken token, WordAnnotation wa) throws IOException { if (token.equals(JsonToken.FIELD_NAME)) { switch (parser.getCurrentName()) { case F_CATEGORY: wa.setCategory(parser.nextTextValue()); break; case F_LEMMA: wa.setLemma(parser.nextTextValue()); break; case F_STEM: wa.setStem(parser.nextTextValue()); break; case F_TAG: wa.setTag(parser.nextTextValue()); break; case F_SUB_CATEGORY: wa.setSubCategory(parser.nextTextValue()); break; case F_REGEX_LABEL: wa.setRegexLabel(parser.nextTextValue()); break; case F_NUMBER: wa.setNumber(parser.nextTextValue()); break; case F_GENDER: wa.setGender(parser.nextTextValue()); break; case F_CASE: wa.setCase(parser.nextTextValue()); break; case F_MOOD: wa.setMood(parser.nextTextValue()); break; case F_TENSE: wa.setTense(parser.nextTextValue()); break; case F_PERSON: wa.setPerson(parser.nextTextValue()); break; case F_DEGREE: wa.setDegree(parser.nextTextValue()); break; case F_FORMATION: wa.setFormation(parser.nextTextValue()); break; case F_LABELS: wa.setLabels(parser.nextTextValue()); break; case F_BEGIN: wa.setBegin(parser.nextIntValue(0)); break; case F_END: wa.setEnd(parser.nextIntValue(0)); break; }//from w w w .ja v a 2 s.c om } }
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)//from w ww. j av a2s .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); }
From source file:data.DefaultExchanger.java
private void importSequence(String dbName, JsonParser parser, JdbcTemplate jdbcTemplate) throws IOException { if (hasSequence()) { JsonToken fieldNameToken = parser.nextToken(); if (fieldNameToken == JsonToken.FIELD_NAME) { String fieldName = parser.getCurrentName(); if (fieldName.equalsIgnoreCase(sequenceName())) { JsonToken current = parser.nextToken(); if (current == JsonToken.VALUE_NUMBER_INT) { long sequenceValue = parser.getNumberValue().longValue(); if (dbName.equals("MySQL")) { jdbcTemplate/*from w w w . ja v a 2 s . c o m*/ .execute("ALTER TABLE " + getTable() + " AUTO_INCREMENT = " + sequenceValue); } else if (dbName.equals("H2")) { jdbcTemplate .execute("ALTER SEQUENCE " + sequenceName() + " RESTART WITH " + sequenceValue); } } } } play.Logger.info("imported sequence {{}}", sequenceName()); } }
From source file:org.mongojack.internal.object.BsonObjectGenerator.java
@Override public void copyCurrentStructure(JsonParser jp) throws IOException { JsonToken t = jp.getCurrentToken();//from w ww.j a v a 2 s. c o m // Let'string handle field-name separately first if (t == JsonToken.FIELD_NAME) { writeFieldName(jp.getCurrentName()); t = jp.nextToken(); // fall-through to copy the associated value } switch (t) { case START_ARRAY: writeStartArray(); while (jp.nextToken() != JsonToken.END_ARRAY) { copyCurrentStructure(jp); } writeEndArray(); break; case START_OBJECT: writeStartObject(); while (jp.nextToken() != JsonToken.END_OBJECT) { copyCurrentStructure(jp); } writeEndObject(); break; default: // others are simple: copyCurrentEvent(jp); } }
From source file:de.undercouch.bson4jackson.BsonParser.java
@Override public JsonToken nextToken() throws IOException, JsonParseException { Context ctx = _currentContext; if (_currToken == null && ctx == null) { try {// www . ja v a2s. co m _currToken = handleNewDocument(false); } catch (EOFException e) { //there is nothing more to read. indicate EOF return null; } } else { _tokenPos = _counter.getPosition(); if (ctx == null) { if (_currToken == JsonToken.END_OBJECT) { //end of input return null; } throw new JsonParseException("Found element outside the document", getTokenLocation()); } if (ctx.state == State.DONE) { //next field ctx.reset(); } boolean readValue = true; if (ctx.state == State.FIELDNAME) { readValue = false; while (true) { //read field name or end of document ctx.type = _in.readByte(); if (ctx.type == BsonConstants.TYPE_END) { //end of document _currToken = (ctx.array ? JsonToken.END_ARRAY : JsonToken.END_OBJECT); _currentContext = _currentContext.parent; } else if (ctx.type == BsonConstants.TYPE_UNDEFINED) { //skip field name and then ignore this token skipCString(); continue; } else { ctx.state = State.VALUE; _currToken = JsonToken.FIELD_NAME; if (ctx.array) { //immediately read value of array element (discard field name) readValue = true; skipCString(); ctx.fieldName = null; } else { //read field name ctx.fieldName = readCString(); } } break; } } if (readValue) { //parse element's value switch (ctx.type) { case BsonConstants.TYPE_DOUBLE: ctx.value = _in.readDouble(); _currToken = JsonToken.VALUE_NUMBER_FLOAT; break; case BsonConstants.TYPE_STRING: ctx.value = readString(); _currToken = JsonToken.VALUE_STRING; break; case BsonConstants.TYPE_DOCUMENT: _currToken = handleNewDocument(false); break; case BsonConstants.TYPE_ARRAY: _currToken = handleNewDocument(true); break; case BsonConstants.TYPE_BINARY: _currToken = handleBinary(); break; case BsonConstants.TYPE_OBJECTID: ctx.value = readObjectId(); _currToken = JsonToken.VALUE_EMBEDDED_OBJECT; break; case BsonConstants.TYPE_BOOLEAN: boolean b = _in.readBoolean(); ctx.value = b; _currToken = (b ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE); break; case BsonConstants.TYPE_DATETIME: ctx.value = new Date(_in.readLong()); _currToken = JsonToken.VALUE_EMBEDDED_OBJECT; break; case BsonConstants.TYPE_NULL: _currToken = JsonToken.VALUE_NULL; break; case BsonConstants.TYPE_REGEX: _currToken = handleRegEx(); break; case BsonConstants.TYPE_DBPOINTER: _currToken = handleDBPointer(); break; case BsonConstants.TYPE_JAVASCRIPT: ctx.value = new JavaScript(readString()); _currToken = JsonToken.VALUE_EMBEDDED_OBJECT; break; case BsonConstants.TYPE_SYMBOL: ctx.value = readSymbol(); _currToken = JsonToken.VALUE_EMBEDDED_OBJECT; break; case BsonConstants.TYPE_JAVASCRIPT_WITH_SCOPE: _currToken = handleJavascriptWithScope(); break; case BsonConstants.TYPE_INT32: ctx.value = _in.readInt(); _currToken = JsonToken.VALUE_NUMBER_INT; break; case BsonConstants.TYPE_TIMESTAMP: ctx.value = readTimestamp(); _currToken = JsonToken.VALUE_EMBEDDED_OBJECT; break; case BsonConstants.TYPE_INT64: ctx.value = _in.readLong(); _currToken = JsonToken.VALUE_NUMBER_INT; break; case BsonConstants.TYPE_MINKEY: ctx.value = "MinKey"; _currToken = JsonToken.VALUE_STRING; break; case BsonConstants.TYPE_MAXKEY: ctx.value = "MaxKey"; _currToken = JsonToken.VALUE_STRING; break; default: throw new JsonParseException("Unknown element type " + ctx.type, getTokenLocation()); } ctx.state = State.DONE; } } return _currToken; }
From source file:org.gvnix.web.json.DataBinderDeserializer.java
/** * Deserializes JSON property into Map<String, String> format to use it in a * Spring {@link DataBinder}.//from w ww . ja v a 2 s. c o m * <p/> * Check token's type to perform an action: * <ul> * <li>If it's a property, stores it in map</li> * <li>If it's an object, calls to * {@link #readObject(JsonParser, DeserializationContext, String)}</li> * <li>If it's an array, calls to * {@link #readArray(JsonParser, DeserializationContext, String)}</li> * </ul> * * @param parser * @param ctxt * @param token current token * @param prefix property dataBinder path * @return * @throws IOException * @throws JsonProcessingException */ protected Map<String, String> readField(JsonParser parser, DeserializationContext ctxt, JsonToken token, String prefix) throws IOException, JsonProcessingException { String fieldName = null; String fieldValue = null; // Read the field name fieldName = parser.getCurrentName(); // If current token contains a field name if (!isEmptyString(fieldName)) { // Append the prefix if given if (isEmptyString(prefix)) { fieldName = parser.getCurrentName(); } else { fieldName = prefix.concat(parser.getCurrentName()); } } // If current token contains mark array or object start markers. // Note it cannot be a field value because it will be read below and // then the token is advanced to the next else { // Use the prefix in recursive calls if (!isEmptyString(prefix)) { fieldName = prefix; } } // If current token has been used to read the field name, advance // stream to the next token that contains the field value if (token == JsonToken.FIELD_NAME) { token = parser.nextToken(); } // Field value switch (token) { case VALUE_STRING: case VALUE_NUMBER_INT: case VALUE_NUMBER_FLOAT: case VALUE_EMBEDDED_OBJECT: case VALUE_TRUE: case VALUE_FALSE: // Plain field: Store value Map<String, String> field = new HashMap<String, String>(); fieldValue = parser.getText(); field.put(fieldName, fieldValue); return field; case START_ARRAY: // Read array items return readArray(parser, ctxt, fieldName); case START_OBJECT: // Read object properties return readObject(parser, ctxt, fieldName); case END_ARRAY: case END_OBJECT: // Skip array and object end markers parser.nextToken(); break; default: throw ctxt.mappingException(getBeanClass()); } return Collections.emptyMap(); }
From source file:io.syndesis.jsondb.impl.SqlJsonDB.java
@Override public void update(String path, InputStream is) { ArrayList<String> updatePaths = new ArrayList<>(); withTransaction(dbi -> {/*from w ww . ja v a 2s . c o m*/ try { BatchManager mb = new BatchManager(dbi); try (JsonParser jp = new JsonFactory().createParser(is)) { JsonToken nextToken = jp.nextToken(); if (nextToken != JsonToken.START_OBJECT) { throw new JsonParseException(jp, "Update did not contain a json object"); } while (true) { nextToken = jp.nextToken(); if (nextToken == JsonToken.END_OBJECT) { break; } if (nextToken != JsonToken.FIELD_NAME) { throw new JsonParseException(jp, "Expected a field name"); } String key = Strings.suffix(path, "/") + jp.getCurrentName(); updatePaths.add(key); String baseDBPath = JsonRecordSupport.convertToDBPath(key); mb.deleteRecordsForSet(baseDBPath); try { JsonRecordSupport.jsonStreamToRecords(jp, baseDBPath, mb.createSetConsumer()); } catch (IOException e) { throw new JsonDBException(e); } } nextToken = jp.nextToken(); if (nextToken != null) { throw new JsonParseException(jp, "Document did not terminate as expected."); } mb.flush(); } } catch (IOException e) { throw new JsonDBException(e); } }); if (bus != null) { for (String updatePath : updatePaths) { bus.broadcast("jsondb-updated", Strings.prefix(Strings.trimSuffix(updatePath, "/"), "/")); } } }
From source file:eu.project.ttc.readers.TermSuiteJsonCasDeserializer.java
private static void fillSdi(JsonParser parser, JsonToken token, SourceDocumentInformation sdi) throws IOException { if (token.equals(JsonToken.FIELD_NAME)) { switch (parser.getCurrentName()) { case F_URI: sdi.setUri(parser.nextTextValue()); break; case F_OFFSET_IN_SOURCE: sdi.setOffsetInSource(parser.nextIntValue(0)); break; case F_DOCUMENT_INDEX: sdi.setDocumentIndex(parser.nextIntValue(0)); break; case F_NB_DOCUMENTS: sdi.setNbDocuments(parser.nextIntValue(0)); break; case F_DOCUMENT_SIZE: sdi.setDocumentSize(parser.nextIntValue(0)); break; case F_CUMULATED_DOCUMENT_SIZE: sdi.setCumulatedDocumentSize(parser.nextLongValue(0)); break; case F_CORPUS_SIZE: sdi.setCorpusSize(parser.nextLongValue(0)); break; case F_LAST_SEGMENT: sdi.setLastSegment(parser.nextBooleanValue()); break; case F_BEGIN: sdi.setBegin(parser.nextIntValue(0)); break; case F_END: sdi.setEnd(parser.nextIntValue(0)); break; }/* ww w. j a v a 2 s . com*/ } }