當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonParser.nextToken方法代碼示例

本文整理匯總了Java中com.fasterxml.jackson.core.JsonParser.nextToken方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonParser.nextToken方法的具體用法?Java JsonParser.nextToken怎麽用?Java JsonParser.nextToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.fasterxml.jackson.core.JsonParser的用法示例。


在下文中一共展示了JsonParser.nextToken方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
public static YieldMessage deserialize(JsonParser jp) throws IOException {
	jp.nextToken();
	long request = jp.getLongValue();

	jp.nextToken();
	ParserUtil.readObject(jp);

	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 YieldMessage(request, arguments, argumentsKw);
}
 
開發者ID:ralscha,項目名稱:wamp2spring,代碼行數:22,代碼來源:YieldMessage.java

示例2: parse

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public MultipleFieldNamesModel parse(JsonParser jsonParser) throws IOException {
    MultipleFieldNamesModel instance = new MultipleFieldNamesModel();
    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,代碼行數:19,代碼來源:MultipleFieldNamesModel$$JsonObjectMapper.java

示例3: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public Contingency deserialize(JsonParser parser, DeserializationContext ctx) throws IOException {
    String id = null;
    List<ContingencyElement> elements = Collections.emptyList();

    while (parser.nextToken() != JsonToken.END_OBJECT) {
        switch (parser.getCurrentName()) {
            case "id":
                id = parser.nextTextValue();
                break;

            case "elements":
                parser.nextToken();
                elements = parser.readValueAs(new TypeReference<ArrayList<ContingencyElement>>() {
                });
                break;

            default:
                throw new AssertionError("Unexpected field: " + parser.getCurrentName());
        }
    }

    return new ContingencyImpl(id, elements);
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:25,代碼來源:ContingencyDeserializer.java

示例4: merge

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
/**
 * Parse a text-format message from {@code input} and merge the contents into {@code builder}.
 * Extensions will be recognized if they are registered in {@code extensionRegistry}.
 * @throws IOException
 */
public void merge(JsonParser parser,
						 ExtensionRegistry extensionRegistry,
                         Message.Builder builder) throws IOException {

    JsonToken token = parser.nextToken();
    if (token.equals(JsonToken.START_OBJECT)) {
    	token = parser.nextToken();
    }
    while (token != null && !token.equals(JsonToken.END_OBJECT)) {
    	mergeField(parser, extensionRegistry, builder);
    	token = parser.nextToken();
    }

    // Test to make sure the tokenizer has reached the end of the stream.
    if (parser.nextToken() != null) {
        throw new RuntimeException("Expecting the end of the stream, but there seems to be more data!  Check the input for a valid JSON format.");
    }
}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:24,代碼來源:JsonJacksonFormat.java

示例5: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@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,代碼行數:19,代碼來源:JacksonConverterFactoryTest.java

示例6: parse

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public PrePostProcessingModel parse(JsonParser jsonParser) throws IOException {
    PrePostProcessingModel instance = new PrePostProcessingModel();
    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();
    }
    instance.onParseComplete();
    return instance;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:PrePostProcessingModel$$JsonObjectMapper.java

示例7: parse

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@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,代碼行數:19,代碼來源:PrivateFieldModel$$JsonObjectMapper.java

示例8: parseRepo

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
private HashMap<String, Object> parseRepo(ObjectMapper mapper, JsonParser parser) throws IOException {
    TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() {
    };
    parser.nextToken();
    parser.nextToken();
    return mapper.readValue(parser, typeRef);
}
 
開發者ID:uhuru-mobile,項目名稱:mobile-store,代碼行數:8,代碼來源:IndexV1Updater.java

示例9: loadPart

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
private static Part loadPart(int index, JsonParser parser, double location) throws IOException {
    if (parser.nextToken() != JsonToken.FIELD_NAME) {
        throw new IOException( "Field name expected.");
    }
    if (!Objects.equals(parser.getCurrentName(), "length")) {
        throw new IOException("length field expected.");
    }

    parser.nextToken();
    double length = parser.getDoubleValue();

    if (parser.nextToken() != JsonToken.FIELD_NAME) {
        throw new IOException("Field name expected.");
    }
    if (!Objects.equals(parser.getCurrentName(), "type")) {
        throw new IOException("type field expected.");
    }

    parser.nextToken();
    String val = parser.getText();
    Part.TYPE type;
    if (Objects.equals(val, "s")) {
        type = Part.TYPE.STRAIGHT;
    } else if (Objects.equals(val, "c")) {
        type = Part.TYPE.CURVED;
    } else {
        throw new IOException("Invalid part type detected.");
    }
    if (parser.nextToken() != JsonToken.END_OBJECT) {
        throw new IOException("Expected object to end.");
    }

    return new Part(index, type, length, location);
}
 
開發者ID:pushtechnology,項目名稱:racing-demo,代碼行數:35,代碼來源:RaceTrack.java

示例10: skip

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
/**
 * Skip a part of a JSON document
 */
public static void skip(JsonParser parser) throws IOException {
    int objectCount = 0;
    do {
        JsonToken token = parser.nextToken();
        if (token == JsonToken.START_OBJECT) {
            objectCount++;
        } else if (token == JsonToken.END_OBJECT) {
            objectCount--;
        }
    } while (objectCount != 0);
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:15,代碼來源:JsonUtil.java

示例11: parseArray

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
private Object[] parseArray(JsonParser parser, DeserializationContext context) throws IOException,
	JsonProcessingException
{
	boolean started = false;
	final List<Object> values = Lists.newArrayList();
	while( parser.hasCurrentToken() )
	{
		final JsonToken currentToken = parser.getCurrentToken();
		switch( currentToken )
		{
			case START_ARRAY:
				if( started )
				{
					values.add(parseArray(parser, context));
				}
				started = true;
				break;
			case END_ARRAY:
				if( !started )
				{
					throw context.mappingException("End array encountered without start " + where(parser, context));
				}
				return values.toArray();
			case NOT_AVAILABLE:
				break;
			default:
				if( !started )
				{
					throw context.mappingException("Value encountered without array start "
						+ where(parser, context));
				}
				values.add(parse(parser, context));
		}
		parser.nextToken();
	}
	throw context.mappingException("No end array found " + where(parser, context));
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:38,代碼來源:MapDeserialiser.java

示例12: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
	public List<DataPointRequest> deserialize(JsonParser parser, DeserializationContext deserializationContext) throws IOException
{
		List<DataPointRequest> datapoints = new ArrayList<DataPointRequest>();

		JsonToken token = parser.nextToken();
		if (token != JsonToken.START_ARRAY )
			throw deserializationContext.mappingException("Invalid data point syntax.");

	while(token != null && token != JsonToken.END_ARRAY)
		{
		 	parser.nextToken();
			long timestamp = parser.getLongValue();

			parser.nextToken();
			String value = parser.getText();

			DataPointRequest dataPointRequest = new DataPointRequest(timestamp, value);

			validateObject(dataPointRequest);
			datapoints.add(dataPointRequest);

			token = parser.nextToken();
			if (token != JsonToken.END_ARRAY)
				throw deserializationContext.mappingException("Invalid data point syntax.");

			token = parser.nextToken();
		}

		return datapoints;
	}
 
開發者ID:quqiangsheng,項目名稱:abhot,代碼行數:32,代碼來源:DataPointDeserializer.java

示例13: parseFieldName

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
private static void parseFieldName(JsonParser jsonParser, JsonParsingContext parsingContext) throws IOException {
    switch (jsonParser.getCurrentName()) {
        case NodeGenericMetadataJsonSerializer.TYPE:
            jsonParser.nextToken();
            parsingContext.type = jsonParser.getValueAsString();
            break;

        case NodeGenericMetadataJsonSerializer.NAME:
            jsonParser.nextToken();
            parsingContext.name = jsonParser.getValueAsString();
            break;

        case NodeGenericMetadataJsonSerializer.VALUE:
            Objects.requireNonNull(parsingContext.name);
            Objects.requireNonNull(parsingContext.type);
            jsonParser.nextToken();
            switch (parsingContext.type) {
                case NodeGenericMetadataJsonSerializer.STRING:
                    parsingContext.metadata.setString(parsingContext.name, jsonParser.getValueAsString());
                    break;
                case NodeGenericMetadataJsonSerializer.DOUBLE:
                    parsingContext.metadata.setDouble(parsingContext.name, jsonParser.getValueAsDouble());
                    break;
                case NodeGenericMetadataJsonSerializer.INT:
                    parsingContext.metadata.setInt(parsingContext.name, jsonParser.getValueAsInt());
                    break;
                case NodeGenericMetadataJsonSerializer.BOOLEAN:
                    parsingContext.metadata.setBoolean(parsingContext.name, jsonParser.getValueAsBoolean());
                    break;
                default:
                    throw new AssertionError("Unexpected metadata type " + parsingContext.type);
            }
            break;

        default:
            throw new AssertionError("Unexpected field: " + jsonParser.getCurrentName());

    }
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:40,代碼來源:NodeGenericMetadataJsonDeserializer.java

示例14: parsePerson

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
public void parsePerson(JsonParser parser) throws IOException {
    while (parser.nextToken() != JsonToken.END_ARRAY) {
        String token = parser.getCurrentName();
        if ("firstname".equals(token)) {
            parser.nextToken();
            String fname = parser.getText();
            out.println("firstname : " + fname);
        }
        if ("lastname".equals(token)) {
            parser.nextToken();
            String lname = parser.getText();
            out.println("lastname : " + lname);
        }
        if ("phone".equals(token)) {
            parser.nextToken();
            long phone = parser.getLongValue();
            out.println("phone : " + phone);
        }
        if ("address".equals(token)) {
            out.println("address :");
            parser.nextToken();
            while (parser.nextToken() != JsonToken.END_ARRAY) {
                out.println(parser.getText());
            }
        }
    }
}
 
開發者ID:PacktPublishing,項目名稱:Java-Data-Science-Made-Easy,代碼行數:28,代碼來源:JSONExamples.java

示例15: parseMap

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
/**
 * Parse a map of objects from a String. Note: parsing from an InputStream should be preferred over parsing from a String if possible.
 *
 * @param jsonString The JSON string being parsed.
 */
public Map<String, T> parseMap(String jsonString) throws IOException {
    JsonParser jsonParser = LoganSquare.JSON_FACTORY.createParser(jsonString);
    jsonParser.nextToken();
    return parseMap(jsonParser);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:JsonMapper.java


注:本文中的com.fasterxml.jackson.core.JsonParser.nextToken方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。