本文整理匯總了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();
}