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


Java JsonParser.hasCurrentToken方法代码示例

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


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

示例1: deserialize

import com.fasterxml.jackson.core.JsonParser; //导入方法依赖的package包/类
@Override
public Map<String, Object> deserialize(JsonParser parser, DeserializationContext context) throws IOException,
	JsonProcessingException
{
	final Map<String, Object> map = Maps.newHashMap();
	int times = 0;
	while( parser.hasCurrentToken() )
	{
		final JsonToken currentToken = parser.getCurrentToken();
		switch( currentToken )
		{
			case START_OBJECT:
				// sure
				times++;
				if( times > 1 )
				{
					throw context.mappingException("Object opened twice??");
				}
				break;

			case END_OBJECT:
				return map;

			case FIELD_NAME:
				parser.nextToken();
				map.put(parser.getCurrentName(), parse(parser, context));
				break;

			case NOT_AVAILABLE:
				parser.nextToken();
				break;

			default:
				throw context.mappingException("Object can only contain fields " + where(parser, context));
		}
		parser.nextToken();
	}
	throw context.mappingException("No end object encountered " + where(parser, context));
}
 
开发者ID:equella,项目名称:Equella,代码行数:40,代码来源:MapDeserialiser.java

示例2: 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

示例3: deserialize

import com.fasterxml.jackson.core.JsonParser; //导入方法依赖的package包/类
@Override
public ObjectExpression deserialize(JsonParser parser, DeserializationContext context) throws IOException,
	JsonProcessingException
{
	final ObjectExpression map = new ObjectExpression();
	int times = 0;
	while( parser.hasCurrentToken() )
	{
		final JsonToken currentToken = parser.getCurrentToken();
		switch( currentToken )
		{
			case START_OBJECT:
				// sure
				times++;
				if( times > 1 )
				{
					throw context.mappingException("Object opened twice??");
				}
				break;

			case END_OBJECT:
				return map;

			case FIELD_NAME:
				parser.nextToken();
				map.put(parser.getCurrentName(), parse(parser, context));
				break;

			case NOT_AVAILABLE:
				parser.nextToken();
				break;

			default:
				throw context.mappingException("Object can only contain fields " + where(parser, context));
		}
		parser.nextToken();
	}
	throw context.mappingException("No end object encountered " + where(parser, context));
}
 
开发者ID:equella,项目名称:Equella,代码行数:40,代码来源:ObjectExpressionDeserialiser.java

示例4: parseArray

import com.fasterxml.jackson.core.JsonParser; //导入方法依赖的package包/类
private ArrayExpression 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 new ArrayExpression(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,代码来源:ObjectExpressionDeserialiser.java


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