当前位置: 首页>>代码示例>>Java>>正文


Java JsonToken.START_OBJECT属性代码示例

本文整理汇总了Java中com.fasterxml.jackson.core.JsonToken.START_OBJECT属性的典型用法代码示例。如果您正苦于以下问题:Java JsonToken.START_OBJECT属性的具体用法?Java JsonToken.START_OBJECT怎么用?Java JsonToken.START_OBJECT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.fasterxml.jackson.core.JsonToken的用法示例。


在下文中一共展示了JsonToken.START_OBJECT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deserialize

@Override public AnInterface deserialize(JsonParser jp, DeserializationContext ctxt)
    throws IOException {
  if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
    throw new AssertionError("Expected start object.");
  }

  String name = null;

  while (jp.nextToken() != JsonToken.END_OBJECT) {
    switch (jp.getCurrentName()) {
      case "name":
        name = jp.getValueAsString();
        break;
    }
  }

  return new AnImplementation(name);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:JacksonConverterFactoryTest.java

示例2: parse

@Override
public ParentModel parse(JsonParser jsonParser) throws IOException {
    ParentModel instance = new ParentModel();
    if (jsonParser.getCurrentToken() == null) {
        jsonParser.nextToken();
    }
    if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) {
        jsonParser.skipChildren();
        return null;
    }
    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
        String fieldName = jsonParser.getCurrentName();
        jsonParser.nextToken();
        parseField(instance, fieldName, jsonParser);
        jsonParser.skipChildren();
    }
    return instance;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:ParentModel$$JsonObjectMapper.java

示例3: parse

@Override
public PrivateFieldModel parse(JsonParser jsonParser) throws IOException {
    PrivateFieldModel instance = new PrivateFieldModel();
    if (jsonParser.getCurrentToken() == null) {
        jsonParser.nextToken();
    }
    if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) {
        jsonParser.skipChildren();
        return null;
    }
    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
        String fieldName = jsonParser.getCurrentName();
        jsonParser.nextToken();
        parseField(instance, fieldName, jsonParser);
        jsonParser.skipChildren();
    }
    return instance;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:PrivateFieldModel$$JsonObjectMapper.java

示例4: parse

@Override
public SimpleModel parse(JsonParser jsonParser) throws IOException {
    SimpleModel instance = new SimpleModel();
    if (jsonParser.getCurrentToken() == null) {
        jsonParser.nextToken();
    }
    if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) {
        jsonParser.skipChildren();
        return null;
    }
    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
        String fieldName = jsonParser.getCurrentName();
        jsonParser.nextToken();
        parseField(instance, fieldName, jsonParser);
        jsonParser.skipChildren();
    }
    return instance;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:SimpleModel$$JsonObjectMapper.java

示例5: deserialize

public static UnsubscribedMessage deserialize(JsonParser jp) throws IOException {
	jp.nextToken();
	long request = jp.getLongValue();

	Long subscriptionId = null;
	String reason = null;

	JsonToken token = jp.nextToken();
	if (token == JsonToken.START_OBJECT) {
		Map<String, Object> details = ParserUtil.readObject(jp);
		reason = (String) details.get("reason");

		Object subscriptionObj = details.get("subscription");
		if (subscriptionObj != null) {
			subscriptionId = ((Number) subscriptionObj).longValue();
		}
	}

	return new UnsubscribedMessage(request, subscriptionId, reason);
}
 
开发者ID:ralscha,项目名称:wamp2spring,代码行数:20,代码来源:UnsubscribedMessage.java

示例6: deserialize

public static InvocationMessage deserialize(JsonParser jp) throws IOException {
	jp.nextToken();
	long request = jp.getLongValue();

	jp.nextToken();
	long registration = jp.getLongValue();

	jp.nextToken();
	Number caller = null;
	Map<String, Object> details = ParserUtil.readObject(jp);
	if (details != null) {
		caller = (Number) details.get("caller");
	}

	List<Object> arguments = null;
	JsonToken token = jp.nextToken();
	if (token == JsonToken.START_ARRAY) {
		arguments = ParserUtil.readArray(jp);
	}

	Map<String, Object> argumentsKw = null;
	token = jp.nextToken();
	if (token == JsonToken.START_OBJECT) {
		argumentsKw = ParserUtil.readObject(jp);
	}

	return new InvocationMessage(request, registration, caller, arguments,
			argumentsKw);
}
 
开发者ID:ralscha,项目名称:wamp2spring,代码行数:29,代码来源:InvocationMessage.java

示例7: mergeValue

void mergeValue(JsonParser parser, int currentDepth, Message.Builder builder) throws IOException {
  ParseSupport.checkRecursionLimit(currentDepth);
  JsonToken json = parser.currentToken();
  if (json == null) {
    // Nested messages will already have current token set, but top-level ones will not.
    json = parser.nextToken();
  }
  if (json != JsonToken.START_OBJECT) {
    throw new InvalidProtocolBufferException(
        "Expected start of object, got: " + parser.getText());
  }
  doMerge(parser, currentDepth, builder);
  // Object end will be handled in ParseSupport.checkObjectEnd.
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:14,代码来源:TypeSpecificMarshaller.java

示例8: parseObjectStart

/**
 * Checks the current token is '{' and advances past it. For parsing the beginning of JSON objects
 * ({@link Message}s and {@link java.util.Map}s).
 */
static void parseObjectStart(JsonParser parser) throws IOException {
  JsonToken json = parser.currentToken();
  if (json != JsonToken.START_OBJECT) {
    throw new InvalidProtocolBufferException("Expected an object but found: " + json);
  }
  parser.nextToken();
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:11,代码来源:ParseSupport.java

示例9: writeDeclaredList

private void writeDeclaredList(ListWriter list, FieldSelection selection, FieldReadDefinition readDef, SchemaPath path, boolean startList, boolean allowNestList) throws IOException {
  if(startList && allowNestList){
    list.startList();
  }
  while (true) {
    try {
      JsonToken token = parser.nextToken();
      if (token == JsonToken.START_ARRAY) {
        boolean innerAllowNestList = readDef.isArray() || readDef.isGeo();
        writeDeclaredList(innerAllowNestList ? list.list() : list, selection, readDef, path, true, innerAllowNestList);
      } else if (token == JsonToken.END_ARRAY) {
        break;
      } else if (token == JsonToken.END_OBJECT) {
        continue;
      } else if (token == JsonToken.START_OBJECT) {
        writeDeclaredMap(list.map(), selection, readDef, true, path, false);
      } else {
        readDef.writeList(list, token, parser);
      }
    } catch (Exception e) {
      throw getExceptionWithContext(e, this.currentFieldName, null).build(logger);
    }
  }

  if(startList && allowNestList){
    list.endList();
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:28,代码来源:ElasticsearchJsonReader.java

示例10: jsonToHostDefinition

protected void jsonToHostDefinition(String json, HostDefinition host) throws IOException {
    MappingJsonFactory f = new MappingJsonFactory();
    JsonParser jp;
    
    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;
        else if (n.equals("attachment")) {
            while (jp.nextToken() != JsonToken.END_OBJECT) {
                String field = jp.getCurrentName();
                if (field.equals("id")) {
                    host.attachment = jp.getText();
                } else if (field.equals("mac")) {
                    host.mac = jp.getText();
                }
            }
        }
    }
    
    jp.close();
}
 
开发者ID:nsg-ethz,项目名称:iTAP-controller,代码行数:38,代码来源:HostResource.java

示例11: getEntryNameFromJson

/**
 * Gets the entry name of a flow mod
 * @param fmJson The OFFlowMod in a JSON representation
 * @return The name of the OFFlowMod, null if not found
 * @throws IOException If there was an error parsing the JSON
 */
public static String getEntryNameFromJson(String fmJson) throws IOException{
	MappingJsonFactory f = new MappingJsonFactory();
	JsonParser jp;

	try {
		jp = f.createJsonParser(fmJson);
	} 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 == StaticFlowEntryPusher.COLUMN_NAME)
			return jp.getText();
	}
	return null;
}
 
开发者ID:nsg-ethz,项目名称:iTAP-controller,代码行数:36,代码来源:StaticFlowEntries.java

示例12: arraysParsingDemo

public static void arraysParsingDemo() throws IOException {
    JsonFactory f = new JsonFactory();
    JsonParser jp = f.createParser(new File("user.array.json"));
    ObjectMapper mapper = new ObjectMapper();
    List<User> userArray = new ArrayList<User>();
    jp.nextToken();
    while(jp.nextToken() == JsonToken.START_OBJECT) {
        userArray.add(mapper.readValue(jp, User.class));
    }
    for (User user : userArray) {
        System.out.println("-----");
        System.out.println(user);
    }
}
 
开发者ID:zhubl,项目名称:planless,代码行数:14,代码来源:Main.java

示例13: handle

void handle(final Map<String, ValueMetadata> colMetadataMap) throws IOException {
    String fieldName;
    ValueMetadata columnMetadata;
    JSonConverter converter;
    Value value;

    // Create a new record
    mCurrentRecord = new Record();
    while (mJp.nextToken() != JsonToken.END_OBJECT) {


        if (mJp.getCurrentToken() == JsonToken.FIELD_NAME) {
            fieldName = mJp.getCurrentName();

            // Get column metadata
            if (!colMetadataMap.containsKey(fieldName)){
                throw new IOException("Unable to find columns metadata for columns " + fieldName);
            }

            columnMetadata = colMetadataMap.get(fieldName);

            // Build the data converter and convert
            converter = JSonConverterFactory.buildConverter(columnMetadata);
            value = converter.jsonToColumnValue(mJp, columnMetadata);

            mCurrentRecord.add(value);
        }
        if (mJp.getCurrentToken() == JsonToken.END_ARRAY) {
            // End Array also no records
            break;
        }

    }

    // Go to next token, only if not the end of records
    if (mJp.getCurrentToken() != JsonToken.END_ARRAY) {
        mJp.nextToken();
    }

    if (mJp.getCurrentToken() == JsonToken.START_OBJECT) {
        // The current token is start of object -> new record no change state required
        return;
    } else if (mJp.getCurrentToken() == JsonToken.END_ARRAY) {
        // The current token is end of array -> end of record, end of table, end of database

        // Consume end of object of current table
        mJp.nextToken();
        if(mJp.getCurrentToken() != JsonToken.END_OBJECT){
            throw new IOException("Unable to read end of table expected end of object line :" + mJp.getCurrentLocation().getLineNr());
        }

        // Consume other token to dete end of database
        // if START_OBJECT -> new TableToSync
        // if END_ARRAY -> end of database
        mJp.nextToken();
        if (mJp.getCurrentToken() == JsonToken.START_OBJECT) {
            mState = new StartTableState();
        } else if (mJp.getCurrentToken() == JsonToken.END_ARRAY) {
            mState = new EndState();
        } else {
            throw new IOException("Unable to read start of table expected { or ] line:" + mJp.getCurrentLocation().getLineNr());
        }
    } else {
        throw new IOException("Unexpected token " + mJp.getCurrentToken() + " line:" + mJp.getCurrentLocation().getLineNr());
    }
}
 
开发者ID:claudiodegio,项目名称:dbsync,代码行数:66,代码来源:JSonDatabaseReader.java

示例14: jsonToMember

protected LBMember jsonToMember(String json) throws IOException {
    MappingJsonFactory f = new MappingJsonFactory();
    JsonParser jp;
    LBMember member = new LBMember();
    
    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")) {
            member.id = jp.getText();
            continue;
        } else
        if (n.equals("address")) {
            member.address = IPv4.toIPv4Address(jp.getText());
            continue;
        } else
        if (n.equals("port")) {
            member.port = Short.parseShort(jp.getText());
            continue;
        } else
        if (n.equals("connection_limit")) {
            member.connectionLimit = Integer.parseInt(jp.getText());
            continue;
        } else
        if (n.equals("admin_state")) {
            member.adminState = Short.parseShort(jp.getText());
            continue;
        } else
        if (n.equals("status")) {
            member.status = Short.parseShort(jp.getText());
            continue;
        } else
        if (n.equals("pool_id")) {
            member.poolId = jp.getText();
            continue;
        } 
        
        log.warn("Unrecognized field {} in " +
                "parsing Members", 
                jp.getText());
    }
    jp.close();

    return member;
}
 
开发者ID:nsg-ethz,项目名称:iTAP-controller,代码行数:62,代码来源:MembersResource.java

示例15: writeToVector

private ReadState writeToVector(ComplexWriter writer, JsonToken t) throws IOException {
  switch (t) {
  case START_OBJECT:
    writeDataSwitch(writer.rootAsMap());
    break;
  case START_ARRAY:
    if(inOuterList){
      throw
        getExceptionWithContext(
          UserException.dataReadError(), currentFieldName, null)
        .message("The top level of your document must either be a single array of maps or a set "
          + "of white space delimited maps.")
        .build(logger);
    }

    if(skipOuterList){
      t = parser.nextToken();
      if(t == JsonToken.START_OBJECT){
        inOuterList = true;
        writeDataSwitch(writer.rootAsMap());
      }else{
        throw
          getExceptionWithContext(
            UserException.dataReadError(), currentFieldName, null)
          .message("The top level of your document must either be a single array of maps or a set "
            + "of white space delimited maps.")
          .build(logger);
      }

    }else{
      writeDataSwitch(writer.rootAsList());
    }
    break;
  case END_ARRAY:

    if(inOuterList){
      confirmLast();
      return ReadState.END_OF_STREAM;
    }else{
      throw
        getExceptionWithContext(
          UserException.dataReadError(), currentFieldName, null)
        .message("Failure while parsing JSON.  Ran across unexpected %s.", JsonToken.END_ARRAY)
        .build(logger);
    }

  case NOT_AVAILABLE:
    return ReadState.END_OF_STREAM;
  default:
    throw
      getExceptionWithContext(
        UserException.dataReadError(), currentFieldName, null)
        .message("Failure while parsing JSON.  Found token of [%s].  Drill currently only supports parsing "
            + "json strings that contain either lists or maps.  The root object cannot be a scalar.", t)
        .build(logger);
  }

  return ReadState.WRITE_SUCCEED;

}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:60,代码来源:JsonReader.java


注:本文中的com.fasterxml.jackson.core.JsonToken.START_OBJECT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。