com.fasterxml.jackson.core.JsonToken#FIELD_NAME源码实例Demo

下面列出了com.fasterxml.jackson.core.JsonToken#FIELD_NAME 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: pentaho-kettle   文件: JsonSampler.java
/**
 * 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 );
    }
  }
}
 
源代码2 项目: olingo-odata4   文件: ClientCsdlFunctionImport.java
@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;
}
 
源代码3 项目: olingo-odata4   文件: ClientCsdlDataServices.java
@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;
}
 
源代码4 项目: olingo-odata4   文件: ClientCsdlApply.java
@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;
}
 
源代码5 项目: olingo-odata4   文件: ClientCsdlEdmx.java
@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;
}
 
源代码6 项目: dropbox-sdk-java   文件: DbxOAuthError.java
@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);
}
 
源代码7 项目: emodb   文件: AbstractEmoFieldUDF.java
/**
 * 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;
}
 
源代码8 项目: caravan   文件: CustomProtobufParser.java
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;
}
 
源代码9 项目: ojai   文件: JsonStreamDocumentReader.java
@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;
}
 
源代码10 项目: ibm-cos-sdk-java   文件: IonParser.java
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;
        }
    }
}
 
源代码11 项目: constellation   文件: RecordStoreUtilities.java
/**
 * 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;
}
 
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);
  }
 
源代码13 项目: dremio-oss   文件: VectorOutput.java
boolean hasBinary() throws JsonParseException, IOException {
  JsonToken token = parser.nextToken();
  return token == JsonToken.FIELD_NAME && parser.getText().equals(ExtendedTypeName.BINARY);
}
 
源代码14 项目: floodlight_with_topoguard   文件: PoolsResource.java
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;
}
 
源代码15 项目: olingo-odata4   文件: ClientCsdlProperty.java
@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;
}
 
源代码16 项目: kripton   文件: CountryBindMap.java
/**
 * 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;
}
 
源代码17 项目: kripton   文件: CountryBindMap.java
/**
 * 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;
}
 
源代码18 项目: olingo-odata4   文件: ClientCsdlTerm.java
@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;
}
 
源代码19 项目: powsybl-core   文件: TimeSeries.java
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;
}
 
源代码20 项目: olingo-odata4   文件: ClientCsdlSchema.java
@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;
}