本文整理汇总了Java中com.fasterxml.jackson.core.JsonParser.clearCurrentToken方法的典型用法代码示例。如果您正苦于以下问题:Java JsonParser.clearCurrentToken方法的具体用法?Java JsonParser.clearCurrentToken怎么用?Java JsonParser.clearCurrentToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.core.JsonParser
的用法示例。
在下文中一共展示了JsonParser.clearCurrentToken方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: _testTokenAccess
import com.fasterxml.jackson.core.JsonParser; //导入方法依赖的package包/类
public void _testTokenAccess(JsonFactory jf, boolean useStream) throws Exception
{
final String DOC = "[ ]";
JsonParser jp = useStream ?
jf.createParser(ObjectReadContext.empty(), new ByteArrayInputStream(DOC.getBytes("UTF-8")))
: jf.createParser(ObjectReadContext.empty(), DOC);
assertNull(jp.currentToken());
jp.clearCurrentToken();
assertNull(jp.currentToken());
assertNull(jp.getEmbeddedObject());
assertToken(JsonToken.START_ARRAY, jp.nextToken());
assertToken(JsonToken.START_ARRAY, jp.currentToken());
jp.clearCurrentToken();
assertNull(jp.currentToken());
// Also: no codec defined by default
try {
jp.readValueAsTree();
fail("Should get exception without codec");
} catch (UnsupportedOperationException e) {
verifyException(e, "Operation not supported");
}
jp.close();
}
示例2: _testCurrentName
import com.fasterxml.jackson.core.JsonParser; //导入方法依赖的package包/类
private void _testCurrentName(JsonFactory jf, boolean useStream) throws Exception
{
final String DOC = "{\"first\":{\"second\":3, \"third\":false}}";
JsonParser jp = useStream ?
jf.createParser(ObjectReadContext.empty(), new ByteArrayInputStream(DOC.getBytes("UTF-8")))
: jf.createParser(ObjectReadContext.empty(), new StringReader(DOC));
assertNull(jp.currentToken());
assertToken(JsonToken.START_OBJECT, jp.nextToken());
assertToken(JsonToken.FIELD_NAME, jp.nextToken());
assertEquals("first", jp.currentName());
assertToken(JsonToken.START_OBJECT, jp.nextToken());
assertEquals("first", jp.currentName()); // still the same...
jp.overrideCurrentName("foobar");
assertEquals("foobar", jp.currentName()); // but not any more!
assertToken(JsonToken.FIELD_NAME, jp.nextToken());
assertEquals("second", jp.currentName());
assertToken(JsonToken.VALUE_NUMBER_INT, jp.nextToken());
assertEquals("second", jp.currentName());
assertToken(JsonToken.FIELD_NAME, jp.nextToken());
assertEquals("third", jp.currentName());
assertToken(JsonToken.VALUE_FALSE, jp.nextToken());
assertEquals("third", jp.currentName());
assertToken(JsonToken.END_OBJECT, jp.nextToken());
// should retain overrides, too
assertEquals("foobar", jp.currentName());
assertToken(JsonToken.END_OBJECT, jp.nextToken());
jp.clearCurrentToken();
assertNull(jp.currentToken());
jp.close();
}