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


Java JsonParser.clearCurrentToken方法代碼示例

本文整理匯總了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();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:TestParserOverrides.java

示例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();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:35,代碼來源:TestParserOverrides.java


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