Java Code Examples for com.fasterxml.jackson.core.JsonToken#FIELD_NAME
The following examples show how to use
com.fasterxml.jackson.core.JsonToken#FIELD_NAME .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonSampler.java From pentaho-kettle with Apache License 2.0 | 6 votes |
/** * Sample a json object recursively * * @param jsonParser * @param objectNode * @throws IOException */ private void sampleObject( JsonParser jsonParser, ObjectNode objectNode ) throws IOException { start++; if ( start > configuration.getLines() ) { return; } while ( jsonParser.nextToken() != JsonToken.END_OBJECT ) { if ( start > configuration.getLines() ) { return; } if ( jsonParser.currentToken() == JsonToken.FIELD_NAME ) { String name = jsonParser.getCurrentName(); jsonParser.nextToken(); Object node = getValue( jsonParser, name ); if ( node instanceof ObjectNode ) { sampleObject( jsonParser, (ObjectNode) node ); } if ( node instanceof ArrayNode ) { sampleArray( jsonParser, (ArrayNode) node ); } objectNode.addValue( (Node) node ); } } }
Example 2
Source File: ClientCsdlFunctionImport.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override protected ClientCsdlFunctionImport doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException { final ClientCsdlFunctionImport functImpImpl = new ClientCsdlFunctionImport(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Name".equals(jp.getCurrentName())) { functImpImpl.setName(jp.nextTextValue()); } else if ("Function".equals(jp.getCurrentName())) { functImpImpl.setFunction(jp.nextTextValue()); } else if ("EntitySet".equals(jp.getCurrentName())) { functImpImpl.setEntitySet(jp.nextTextValue()); } else if ("IncludeInServiceDocument".equals(jp.getCurrentName())) { functImpImpl.setIncludeInServiceDocument(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("Annotation".equals(jp.getCurrentName())) { jp.nextToken(); functImpImpl.getAnnotations().add(jp.readValueAs(ClientCsdlAnnotation.class)); } } } return functImpImpl; }
Example 3
Source File: ClientCsdlDataServices.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override protected ClientCsdlDataServices doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException { final ClientCsdlDataServices dataServices = new ClientCsdlDataServices(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("DataServiceVersion".equals(jp.getCurrentName())) { dataServices.setDataServiceVersion(jp.nextTextValue()); } else if ("MaxDataServiceVersion".equals(jp.getCurrentName())) { dataServices.setMaxDataServiceVersion(jp.nextTextValue()); } else if ("Schema".equals(jp.getCurrentName())) { jp.nextToken(); dataServices.getSchemas().add(jp.readValueAs(ClientCsdlSchema.class)); } } } return dataServices; }
Example 4
Source File: ClientCsdlEdmx.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override protected ClientCsdlEdmx doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException { final ClientCsdlEdmx edmx = new ClientCsdlEdmx(); for (; (jp.getCurrentToken() != null && jp.getCurrentToken() != JsonToken.END_OBJECT); jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Version".equals(jp.getCurrentName())) { edmx.setVersion(jp.nextTextValue()); } else if ("DataServices".equals(jp.getCurrentName())) { jp.nextToken(); edmx.setDataServices(jp.readValueAs(ClientCsdlDataServices.class)); } else if ("Reference".equals(jp.getCurrentName())) { jp.nextToken(); edmx.getReferences().add(jp.readValueAs(ClientCsdlReference.class)); } } } return edmx; }
Example 5
Source File: ClientCsdlApply.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Override protected ClientCsdlApply doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException { final ClientCsdlApply apply = new ClientCsdlApply(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Function".equals(jp.getCurrentName())) { apply.setFunction(jp.nextTextValue()); } else if ("Annotation".equals(jp.getCurrentName())) { apply.getAnnotations().add(jp.readValueAs(ClientCsdlAnnotation.class)); } else if (isAnnotationConstExprConstruct(jp)) { apply.getParameters().add(parseAnnotationConstExprConstruct(jp)); } else { apply.getParameters().add(jp.readValueAs(ClientCsdlDynamicExpression.class)); } } } return apply; }
Example 6
Source File: DbxOAuthError.java From dropbox-sdk-java with MIT License | 5 votes |
@Override public final DbxOAuthError read(JsonParser parser) throws IOException, JsonReadException { JsonLocation top = JsonReader.expectObjectStart(parser); String error = null; String errorDescription = null; while (parser.getCurrentToken() == JsonToken.FIELD_NAME) { String fieldName = parser.getCurrentName(); parser.nextToken(); try { if (fieldName.equals("error")) { error = StringReader.readField(parser, fieldName, error); } else if (fieldName.equals("error_description")) { errorDescription = StringReader.readField(parser, fieldName, errorDescription); } else { // Unknown field. Skip over it. JsonReader.skipValue(parser); } } catch (JsonReadException ex) { throw ex.addFieldContext(fieldName); } } JsonReader.expectObjectEnd(parser); if (error == null) { throw new JsonReadException("missing field \"error\"", top); } return new DbxOAuthError(error, errorDescription); }
Example 7
Source File: CustomProtobufParser.java From caravan with Apache License 2.0 | 5 votes |
private JsonToken _handleNestedKey(int tag) throws IOException { int wireType = tag & 0x7; int id = tag >> 3; ProtobufField f; if (_currentField == null || (f = _currentField.nextOrThisIf(id)) == null) { f = _currentMessage.field(id); } // Note: may be null; if so, value needs to be skipped if (f == null) { return _skipUnknownField(id, wireType); } _parsingContext.setCurrentName(f.name); if (!f.isValidFor(wireType)) { _reportIncompatibleType(f, wireType); } // array? if (f.repeated) { if (f.packed) { _state = STATE_ARRAY_START_PACKED; } else { _state = STATE_ARRAY_START; } } else { _state = STATE_NESTED_VALUE; } _currentField = f; return _currToken = JsonToken.FIELD_NAME; }
Example 8
Source File: AbstractEmoFieldUDF.java From emodb with Apache License 2.0 | 5 votes |
/** * Don't materialize the entire parser content, do a targeted search for the value that matches the path. */ private boolean moveParserToField(JsonParser parser, String path) throws IOException { List<String> segments = getFieldPath(path); for (String segment : segments) { if (parser.getCurrentToken() != JsonToken.START_OBJECT) { // Always expect the path to be fields in a JSON map return false; } boolean found = false; JsonToken currentToken = parser.nextToken(); while (!found && currentToken != JsonToken.END_OBJECT) { if (currentToken != JsonToken.FIELD_NAME) { // This should always be a field. Something is amiss. throw new IOException("Field not found at expected location"); } String fieldName = parser.getText(); if (fieldName.equals(segment)) { // Move to the next token, which is the field value found = true; currentToken = parser.nextToken(); } else { parser.nextValue(); currentToken = skipValue(parser); } } if (!found) { // Field was not found return false; } } // The current location in the parser is the value. return true; }
Example 9
Source File: ClientCsdlSchema.java From olingo-odata4 with Apache License 2.0 | 4 votes |
@Override protected ClientCsdlSchema doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException { final ClientCsdlSchema schema = new ClientCsdlSchema(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Namespace".equals(jp.getCurrentName())) { schema.setNamespace(jp.nextTextValue()); } else if ("Alias".equals(jp.getCurrentName())) { schema.setAlias(jp.nextTextValue()); } else if ("ComplexType".equals(jp.getCurrentName())) { jp.nextToken(); schema.getComplexTypes().add(jp.readValueAs(ClientCsdlComplexType.class)); } else if ("EntityType".equals(jp.getCurrentName())) { jp.nextToken(); schema.getEntityTypes().add(jp.readValueAs(ClientCsdlEntityType.class)); } else if ("EnumType".equals(jp.getCurrentName())) { jp.nextToken(); schema.getEnumTypes().add(jp.readValueAs(ClientCsdlEnumType.class)); } else if ("EntityContainer".equals(jp.getCurrentName())) { jp.nextToken(); ClientCsdlEntityContainer entityContainer = jp.readValueAs(ClientCsdlEntityContainer.class); schema.setEntityContainer(entityContainer); } else if ("Action".equals(jp.getCurrentName())) { jp.nextToken(); schema.getActions().add(jp.readValueAs(ClientCsdlAction.class)); } else if ("Function".equals(jp.getCurrentName())) { jp.nextToken(); schema.getFunctions().add(jp.readValueAs(ClientCsdlFunction.class)); } else if ("TypeDefinition".equals(jp.getCurrentName())) { jp.nextToken(); schema.getTypeDefinitions().add(jp.readValueAs(ClientCsdlTypeDefinition.class)); } } else if ("Annotations".equals(jp.getCurrentName())) { jp.nextToken(); schema.getAnnotationGroups().add(jp.readValueAs(ClientCsdlAnnotations.class)); } else if ("Annotation".equals(jp.getCurrentName())) { jp.nextToken(); schema.getAnnotations().add(jp.readValueAs(ClientCsdlAnnotation.class)); } else if ("Term".equals(jp.getCurrentName())) { jp.nextToken(); schema.getTerms().add(jp.readValueAs(ClientCsdlTerm.class)); } } return schema; }
Example 10
Source File: JsonStreamDocumentReader.java From ojai with Apache License 2.0 | 4 votes |
@Override public EventType next() { isExtended = false; 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; }
Example 11
Source File: TimeSeries.java From powsybl-core with Mozilla Public License 2.0 | 4 votes |
static List<TimeSeries> parseJson(JsonParser parser, boolean single) { Objects.requireNonNull(parser); List<TimeSeries> timeSeriesList = new ArrayList<>(); try { TimeSeriesMetadata metadata = null; String name = null; JsonToken token; while ((token = parser.nextToken()) != null) { if (token == JsonToken.FIELD_NAME) { String fieldName = parser.getCurrentName(); switch (fieldName) { case "metadata": metadata = TimeSeriesMetadata.parseJson(parser); break; case "chunks": if (metadata == null) { throw new TimeSeriesException("metadata is null"); } parseChunks(parser, metadata, timeSeriesList); metadata = null; break; case "name": name = parser.nextTextValue(); break; case "expr": Objects.requireNonNull(name); NodeCalc nodeCalc = NodeCalc.parseJson(parser); timeSeriesList.add(new CalculatedTimeSeries(name, nodeCalc)); break; default: break; } } else if (token == JsonToken.END_OBJECT && single) { break; } } } catch (IOException e) { throw new UncheckedIOException(e); } return timeSeriesList; }
Example 12
Source File: ClientCsdlTerm.java From olingo-odata4 with Apache License 2.0 | 4 votes |
@Override protected ClientCsdlTerm doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException { final ClientCsdlTerm term = new ClientCsdlTerm(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Name".equals(jp.getCurrentName())) { term.setName(jp.nextTextValue()); } else if ("Type".equals(jp.getCurrentName())) { term.setType(jp.nextTextValue()); } else if ("BaseTerm".equals(jp.getCurrentName())) { term.setBaseTerm(jp.nextTextValue()); } else if ("DefaultValue".equals(jp.getCurrentName())) { term.setDefaultValue(jp.nextTextValue()); } else if ("Nullable".equals(jp.getCurrentName())) { term.setNullable(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("MaxLength".equals(jp.getCurrentName())) { final String maxLenght = jp.nextTextValue(); term.setMaxLength("max".equalsIgnoreCase(maxLenght) ? Integer.MAX_VALUE : Integer.valueOf(maxLenght)); } else if ("Precision".equals(jp.getCurrentName())) { term.setPrecision(Integer.valueOf(jp.nextTextValue())); } else if ("Scale".equals(jp.getCurrentName())) { final String scale = jp.nextTextValue(); term.setScale("variable".equalsIgnoreCase(scale) || "floating".equalsIgnoreCase(scale) ? 0 : Integer.valueOf(scale)); } else if ("SRID".equals(jp.getCurrentName())) { final String srid = jp.nextTextValue(); if (srid != null) { term.setSrid(SRID.valueOf(srid)); } } else if ("AppliesTo".equals(jp.getCurrentName())) { term.getAppliesTo().addAll(Arrays.asList(StringUtils.split(jp.nextTextValue()))); } else if ("Annotation".equals(jp.getCurrentName())) { jp.nextToken(); term.getAnnotations().add(jp.readValueAs(ClientCsdlAnnotation.class)); } } } return term; }
Example 13
Source File: CountryBindMap.java From kripton with Apache License 2.0 | 4 votes |
/** * parse with jackson */ @Override public Country parseOnJacksonAsString(JsonParser jacksonParser) throws Exception { Country instance = new Country(); String fieldName; if (jacksonParser.getCurrentToken() == null) { jacksonParser.nextToken(); } if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) { jacksonParser.skipChildren(); return instance; } while (jacksonParser.nextToken() != JsonToken.END_OBJECT) { fieldName = jacksonParser.getCurrentName(); jacksonParser.nextToken(); // Parse fields: switch (fieldName) { case "area": // field area (mapped with "area") instance.area=PrimitiveUtils.readLong(jacksonParser.getText(), 0L); break; case "callingCode": // field callingCode (mapped with "callingCode") if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { instance.callingCode=jacksonParser.getText(); } break; case "code": // field code (mapped with "code") if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { instance.code=jacksonParser.getText(); } break; case "id": // field id (mapped with "id") instance.id=PrimitiveUtils.readLong(jacksonParser.getText(), 0L); break; case "name": // field name (mapped with "name") if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { instance.name=jacksonParser.getText(); } break; case "region": // field region (mapped with "region") if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { instance.region=jacksonParser.getText(); } break; case "translatedName": // field translatedName (mapped with "translatedName") if (jacksonParser.currentToken()==JsonToken.START_ARRAY) { HashMap<Translation, String> collection=new HashMap<>(); Translation key=null; String value=null; JsonToken current; String tempValue=null; while (jacksonParser.nextToken() != JsonToken.END_ARRAY) { current=jacksonParser.currentToken(); for (int i=0; i<2 ;i++) { while (current != JsonToken.FIELD_NAME) { current=jacksonParser.nextToken(); } jacksonParser.nextValue(); switch(jacksonParser.getCurrentName()) { case "key": { String tempEnum=jacksonParser.getText(); key=StringUtils.hasText(tempEnum)?Translation.valueOf(tempEnum):null; } break; case "value": tempValue=jacksonParser.getValueAsString(); if (jacksonParser.currentToken()==JsonToken.VALUE_STRING && "null".equals(tempValue)) { value=null; } else { if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { value=jacksonParser.getText(); } } break; } } collection.put(key, value); key=null; value=null; jacksonParser.nextToken(); } instance.translatedName=collection; } break; default: jacksonParser.skipChildren(); break;} } return instance; }
Example 14
Source File: CountryBindMap.java From kripton with Apache License 2.0 | 4 votes |
/** * parse with jackson */ @Override public Country parseOnJacksonAsString(JsonParser jacksonParser) throws Exception { Country instance = new Country(); String fieldName; if (jacksonParser.getCurrentToken() == null) { jacksonParser.nextToken(); } if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) { jacksonParser.skipChildren(); return instance; } while (jacksonParser.nextToken() != JsonToken.END_OBJECT) { fieldName = jacksonParser.getCurrentName(); jacksonParser.nextToken(); // Parse fields: switch (fieldName) { case "area": // field area (mapped with "area") instance.area=PrimitiveUtils.readLong(jacksonParser.getText(), 0L); break; case "callingCode": // field callingCode (mapped with "callingCode") if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { instance.callingCode=jacksonParser.getText(); } break; case "code": // field code (mapped with "code") if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { instance.code=jacksonParser.getText(); } break; case "id": // field id (mapped with "id") instance.id=PrimitiveUtils.readLong(jacksonParser.getText(), 0L); break; case "name": // field name (mapped with "name") if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { instance.name=jacksonParser.getText(); } break; case "region": // field region (mapped with "region") if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { instance.region=jacksonParser.getText(); } break; case "translatedName": // field translatedName (mapped with "translatedName") if (jacksonParser.currentToken()==JsonToken.START_ARRAY) { HashMap<Translation, String> collection=new HashMap<>(); Translation key=null; String value=null; JsonToken current; String tempValue=null; while (jacksonParser.nextToken() != JsonToken.END_ARRAY) { current=jacksonParser.currentToken(); for (int i=0; i<2 ;i++) { while (current != JsonToken.FIELD_NAME) { current=jacksonParser.nextToken(); } jacksonParser.nextValue(); switch(jacksonParser.getCurrentName()) { case "key": { String tempEnum=jacksonParser.getText(); key=StringUtils.hasText(tempEnum)?Translation.valueOf(tempEnum):null; } break; case "value": tempValue=jacksonParser.getValueAsString(); if (jacksonParser.currentToken()==JsonToken.VALUE_STRING && "null".equals(tempValue)) { value=null; } else { if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) { value=jacksonParser.getText(); } } break; } } collection.put(key, value); key=null; value=null; jacksonParser.nextToken(); } instance.translatedName=collection; } break; default: jacksonParser.skipChildren(); break;} } return instance; }
Example 15
Source File: ClientCsdlProperty.java From olingo-odata4 with Apache License 2.0 | 4 votes |
@Override protected ClientCsdlProperty doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException { final ClientCsdlProperty property = new ClientCsdlProperty(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Name".equals(jp.getCurrentName())) { property.setName(jp.nextTextValue()); } else if ("Type".equals(jp.getCurrentName())) { String metadataTypeName = jp.nextTextValue(); if (metadataTypeName.startsWith("Collection(")) { property.setType(metadataTypeName.substring(metadataTypeName.indexOf("(") + 1, metadataTypeName.length() - 1)); property.setCollection(true); } else { property.setType(metadataTypeName); property.setCollection(false); } } else if ("Nullable".equals(jp.getCurrentName())) { property.setNullable(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("DefaultValue".equals(jp.getCurrentName())) { property.setDefaultValue(jp.nextTextValue()); } else if ("MaxLength".equals(jp.getCurrentName())) { final String maxLenght = jp.nextTextValue(); property.setMaxLength("max".equalsIgnoreCase(maxLenght) ? Integer.MAX_VALUE : Integer.valueOf(maxLenght)); } else if ("Precision".equals(jp.getCurrentName())) { property.setPrecision(Integer.valueOf(jp.nextTextValue())); } else if ("Scale".equals(jp.getCurrentName())) { final String scale = jp.nextTextValue(); property.setScale("variable".equalsIgnoreCase(scale) || "floating".equalsIgnoreCase(scale) ? 0 : Integer.valueOf(scale)); } else if ("Unicode".equals(jp.getCurrentName())) { property.setUnicode(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("SRID".equals(jp.getCurrentName())) { final String srid = jp.nextTextValue(); if (srid != null) { property.setSrid(SRID.valueOf(srid)); } } else if ("Annotation".equals(jp.getCurrentName())) { jp.nextToken(); property.getAnnotations().add(jp.readValueAs(ClientCsdlAnnotation.class)); } } } return property; }
Example 16
Source File: PoolsResource.java From floodlight_with_topoguard with Apache License 2.0 | 4 votes |
protected LBPool jsonToPool(String json) throws IOException { if (json==null) return null; MappingJsonFactory f = new MappingJsonFactory(); JsonParser jp; LBPool pool = new LBPool(); try { jp = f.createJsonParser(json); } catch (JsonParseException e) { throw new IOException(e); } jp.nextToken(); if (jp.getCurrentToken() != JsonToken.START_OBJECT) { throw new IOException("Expected START_OBJECT"); } while (jp.nextToken() != JsonToken.END_OBJECT) { if (jp.getCurrentToken() != JsonToken.FIELD_NAME) { throw new IOException("Expected FIELD_NAME"); } String n = jp.getCurrentName(); jp.nextToken(); if (jp.getText().equals("")) continue; if (n.equals("id")) { pool.id = jp.getText(); continue; } if (n.equals("tenant_id")) { pool.tenantId = jp.getText(); continue; } if (n.equals("name")) { pool.name = jp.getText(); continue; } if (n.equals("network_id")) { pool.netId = jp.getText(); continue; } if (n.equals("lb_method")) { pool.lbMethod = Short.parseShort(jp.getText()); continue; } if (n.equals("protocol")) { String tmp = jp.getText(); if (tmp.equalsIgnoreCase("TCP")) { pool.protocol = IPv4.PROTOCOL_TCP; } else if (tmp.equalsIgnoreCase("UDP")) { pool.protocol = IPv4.PROTOCOL_UDP; } else if (tmp.equalsIgnoreCase("ICMP")) { pool.protocol = IPv4.PROTOCOL_ICMP; } continue; } if (n.equals("vip_id")) { pool.vipId = jp.getText(); continue; } log.warn("Unrecognized field {} in " + "parsing Pools", jp.getText()); } jp.close(); return pool; }
Example 17
Source File: VectorOutput.java From dremio-oss with Apache License 2.0 | 4 votes |
boolean hasBinary() throws JsonParseException, IOException { JsonToken token = parser.nextToken(); return token == JsonToken.FIELD_NAME && parser.getText().equals(ExtendedTypeName.BINARY); }
Example 18
Source File: XMLServiceDocumentDeserializer.java From olingo-odata4 with Apache License 2.0 | 4 votes |
protected ResWrap<ServiceDocument> doDeserialize(final JsonParser jp) throws IOException { ServiceDocumentImpl sdoc = new ServiceDocumentImpl(); URI contextURL = null; String metadataETag = null; String base = null; for (; jp.getCurrentToken() != JsonToken.END_OBJECT || !"service".equals(((FromXmlParser) jp).getStaxReader().getLocalName()); jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("base".equals(jp.getCurrentName())) { base = jp.nextTextValue(); } else if ("context".equals(jp.getCurrentName())) { contextURL = URI.create(jp.nextTextValue()); } else if ("metadata-etag".equals(jp.getCurrentName())) { metadataETag = jp.nextTextValue(); } else if ("workspace".equals(jp.getCurrentName())) { jp.nextToken(); jp.nextToken(); if ("title".equals(jp.getCurrentName())) { sdoc.setTitle(getName(jp)); } } else if ("collection".equals(jp.getCurrentName())) { jp.nextToken(); sdoc.getEntitySets().add(deserializeElement(jp, "collection")); } else if ("function-import".equals(jp.getCurrentName())) { jp.nextToken(); sdoc.getFunctionImports().add(deserializeElement(jp, "function-import")); } else if ("singleton".equals(jp.getCurrentName())) { jp.nextToken(); sdoc.getSingletons().add(deserializeElement(jp, "singleton")); } else if ("service-document".equals(jp.getCurrentName())) { jp.nextToken(); sdoc.getRelatedServiceDocuments().add(deserializeElement(jp, "service-document")); } } } sdoc.setMetadata((contextURL == null ? URIUtils.getURI(base, "$metadata") : URIUtils.getURI(base, contextURL.toASCIIString())).toASCIIString()); return new ResWrap<>( contextURL == null ? null : URIUtils.getURI(sdoc.getBaseURI(), contextURL), metadataETag, sdoc); }
Example 19
Source File: RecordStoreUtilities.java From constellation with Apache License 2.0 | 4 votes |
/** * Convert a JSON {@link InputStream} into a {@link RecordStore}. * <p> * The specified JSON stream should contain an array of objects, with each * object being converted to a record in the resulting {@link RecordStore}. * Each field in each object is converted to an entry in the corresponding * record. * * @param in An {@link InputStream} through which the JSON document will be * transported. * @return A {@link RecordStore} derived from the JSON document. * @throws IOException If something goes wrong while reading the JSON * document. */ public static RecordStore fromJson(final InputStream in) throws IOException { final RecordStore recordStore; try (final JsonParser parser = new MappingJsonFactory().createParser(in)) { recordStore = new GraphRecordStore(); JsonToken currentToken = parser.nextToken(); if (currentToken != JsonToken.START_ARRAY) { return null; } while (true) { currentToken = parser.nextToken(); if (currentToken == JsonToken.START_OBJECT) { recordStore.add(); while (true) { currentToken = parser.nextToken(); if (currentToken == JsonToken.FIELD_NAME) { String fieldName = parser.getCurrentName(); String fieldValue; currentToken = parser.nextToken(); if (currentToken == JsonToken.VALUE_STRING || currentToken == JsonToken.VALUE_NUMBER_INT || currentToken == JsonToken.VALUE_NUMBER_FLOAT) { fieldValue = parser.getValueAsString(); } else { return null; } recordStore.set(fieldName, fieldValue); } else if (currentToken == JsonToken.END_OBJECT) { break; } else { return null; } } } else if (currentToken == JsonToken.END_ARRAY) { break; } else { return null; } } } return recordStore; }
Example 20
Source File: IonParser.java From ibm-cos-sdk-java with Apache License 2.0 | 4 votes |
private JsonToken doNextToken() { for (;;) { switch (state) { case BEFORE_VALUE: IonType currentType = reader.next(); if (currentType == null) { boolean topLevel = reader.getDepth() == 0; if (topLevel) { state = State.EOF; continue; } else { state = State.END_OF_CONTAINER; return reader.isInStruct() ? JsonToken.END_OBJECT : JsonToken.END_ARRAY; } } if (reader.isInStruct()) { state = State.FIELD_NAME; return JsonToken.FIELD_NAME; } else { state = State.VALUE; return getJsonToken(); } case END_OF_CONTAINER: reader.stepOut(); state = State.BEFORE_VALUE; continue; case EOF: return null; case FIELD_NAME: state = State.VALUE; return getJsonToken(); case VALUE: state = State.BEFORE_VALUE; if (IonType.isContainer(reader.getType()) && !reader.isNullValue() && !shouldSkipContainer) { reader.stepIn(); } shouldSkipContainer = false; continue; } } }