本文整理汇总了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);
}
示例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;
}
示例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);
}
示例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.");
}
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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));
}
示例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;
}
示例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());
}
}
示例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());
}
}
}
}
示例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);
}