当前位置: 首页>>代码示例>>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;未经允许,请勿转载。