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


Java JsonToken类代码示例

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


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

示例1: parseInt32

import com.fasterxml.jackson.core.JsonToken; //导入依赖的package包/类
/** Parsers an int32 value out of the input. */
static int parseInt32(JsonParser parser) throws IOException {
  JsonToken token = parser.currentToken();
  if (token == JsonToken.VALUE_NUMBER_INT) {
    // Use optimized code path for integral primitives, the normal case.
    return parser.getIntValue();
  }
  // JSON doesn't distinguish between integer values and floating point values so "1" and
  // "1.000" are treated as equal in JSON. For this reason we accept floating point values for
  // integer fields as well as long as it actually is an integer (i.e., round(value) == value).
  try {
    BigDecimal value =
        new BigDecimal(
            parser.getTextCharacters(), parser.getTextOffset(), parser.getTextLength());
    return value.intValueExact();
  } catch (Exception e) {
    throw new InvalidProtocolBufferException("Not an int32 value: " + parser.getText());
  }
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:20,代码来源:ParseSupport.java

示例2: parse

import com.fasterxml.jackson.core.JsonToken; //导入依赖的package包/类
/**
 * @param content
 * @throws JsonParseException
 * @throws IOException
 */
public PageInstance parse(String content) throws JsonParseException, IOException {
    JsonFactory f = new JsonFactory();
    JsonParser parser = f.createJsonParser(content);

    JsonToken current = parser.nextToken(); // move to the start of the
    // object

    String instanceId = getNextTextValue("sid", parser); // get instanceId

    String pageId = getNextTextValue("cid", parser); // get pageId

    current = parser.nextToken(); // move to field: segments
    assertExpectedFiled(parser.getCurrentName(), "segments", parser.getCurrentLocation());

    PageInstance pageInstance = new PageInstance();
    pageInstance.setCid(pageId);
    pageInstance.setSid(Long.valueOf(instanceId));
    pageInstance.setSegments(parseSegments(parser));
    return pageInstance;
    // 构建组件树,用于递归渲染
    // pageInstance.buildComponentTree();

}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:JacksonPageModelParser.java

示例3: unmarshallJsonToList

import com.fasterxml.jackson.core.JsonToken; //导入依赖的package包/类
/**
 * Unmarshalls the current token in the Json document to list.
 */
private List<T> unmarshallJsonToList(JsonUnmarshallerContext context)
        throws Exception {
    List<T> list = new ArrayList<T>();

    if (context.getCurrentToken() == JsonToken.VALUE_NULL) {
        return null;
    }

    while (true) {
        JsonToken token = context.nextToken();
        if (token == null) {
            return list;
        }

        if (token == END_ARRAY) {
            return list;
        } else {
            list.add(itemUnmarshaller.unmarshall(context));
        }
    }
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:25,代码来源:ListUnmarshaller.java

示例4: testGetCurrentNameNotAtFieldReturnsNull

import com.fasterxml.jackson.core.JsonToken; //导入依赖的package包/类
@Test
public void testGetCurrentNameNotAtFieldReturnsNull() throws IOException {
    IonParser parser = parse("{foo:\"abc\"} [a, b] {{}} \"bar\"");
    assertEquals(JsonToken.START_OBJECT, parser.nextToken());
    assertNull(parser.getCurrentName());
    assertEquals(JsonToken.VALUE_STRING, parser.nextValue());
    assertEquals(JsonToken.END_OBJECT, parser.nextToken());
    assertNull(parser.getCurrentName());
    assertEquals(JsonToken.START_ARRAY, parser.nextToken());
    assertEquals(JsonToken.VALUE_STRING, parser.nextToken());
    assertNull(parser.getCurrentName());
    assertEquals(JsonToken.VALUE_STRING, parser.nextToken());
    assertNull(parser.getCurrentName());
    assertEquals(JsonToken.END_ARRAY, parser.nextToken());
    assertNull(parser.getCurrentName());
    assertEquals(JsonToken.VALUE_EMBEDDED_OBJECT, parser.nextToken());
    assertNull(parser.getCurrentName());
    assertEquals(JsonToken.VALUE_STRING, parser.nextToken());
    assertNull(parser.getCurrentName());
    assertNull(parser.nextToken());
    assertNull(parser.getCurrentName());
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:23,代码来源:IonParserTest.java

示例5: readArray

import com.fasterxml.jackson.core.JsonToken; //导入依赖的package包/类
@Nullable
public static List<Object> readArray(JsonParser jp) throws IOException {
	if (jp.currentToken() != JsonToken.START_ARRAY) {
		return null;
	}

	List<Object> result = new ArrayList<>();
	JsonToken token = jp.nextToken();
	while (token != JsonToken.END_ARRAY) {

		if (token == JsonToken.START_ARRAY) {
			result.add(readArray(jp));
		}
		else if (token == JsonToken.START_OBJECT) {
			result.add(readObject(jp));
		}
		else {
			result.add(getValue(jp));
		}

		token = jp.nextToken();
	}

	return result;
}
 
开发者ID:ralscha,项目名称:wamp2spring,代码行数:26,代码来源:ParserUtil.java

示例6: test_parsePosNumber

import com.fasterxml.jackson.core.JsonToken; //导入依赖的package包/类
@Test
public void test_parsePosNumber() throws IOException {
    byte[] byteArray = new byte[2];
    byteArray[0] = (byte) 51;
    byteArray[1] = (byte) 22;
    IOContext ioContext = new IOContext(new BufferRecycler(), byteArray, false);
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
    ByteQuadsCanonicalizer byteQuadsCanonicalizer = ByteQuadsCanonicalizer.createRoot();
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(),
            ioContext, 1568, dataInputStream, byteQuadsCanonicalizer, 13);
    JsonToken jsonToken = uTF8DataInputJsonParser._parsePosNumber(7);

    assertEquals(7, jsonToken.id());
    assertNull(jsonToken.asString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:UTF8DataInputJsonParserTest.java

示例7: testSurrogatesWithRaw

import com.fasterxml.jackson.core.JsonToken; //导入依赖的package包/类
public void testSurrogatesWithRaw() throws Exception
{
    final String VALUE = quote("\ud83d\ude0c");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    JsonGenerator g = JSON_F.createGenerator(ObjectWriteContext.empty(), out);
    g.writeStartArray();
    g.writeRaw(VALUE);
    g.writeEndArray();
    g.close();

    final byte[] JSON = out.toByteArray();

    JsonParser jp = JSON_F.createParser(ObjectReadContext.empty(), JSON);
    assertToken(JsonToken.START_ARRAY, jp.nextToken());
    assertToken(JsonToken.VALUE_STRING, jp.nextToken());
    String str = jp.getText();
    assertEquals(2, str.length());
    assertEquals((char) 0xD83D, str.charAt(0));
    assertEquals((char) 0xDE0C, str.charAt(1));
    assertToken(JsonToken.END_ARRAY, jp.nextToken());
    jp.close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:TestUtf8Generator.java

示例8: parseInputArrayOfStrings

import com.fasterxml.jackson.core.JsonToken; //导入依赖的package包/类
private void parseInputArrayOfStrings(final JsonParser parser,
                                      final List<String> inputs,
                                      final DriverCache cache,
                                      final Set<ValueGroup> groups) {
    EhSupport.propagate(() -> {
        parser.nextToken();
        while (parser.nextToken() != JsonToken.END_ARRAY) {
            String value = parser.getText();
            if (value.startsWith(GroupDriver.VG_PREFIX) && !cache.contains(value)) {
                final String groupName = value.split(":")[1];
                final Optional<ValueGroup> group =
                        groups.stream().filter(valueGroup -> valueGroup.getName().equals(groupName)).findFirst();
                if (group.isPresent()) {
                    value = GroupDriver.VG_PREFIX + group.get().getId();
                } else {
                    inputs.add(value);
                }
            }
            inputs.add(value);
        }
    });
}
 
开发者ID:jpmorganchase,项目名称:swblocks-decisiontree,代码行数:23,代码来源:JsonJacksonParser.java

示例9: testToDoubleCoercion

import com.fasterxml.jackson.core.JsonToken; //导入依赖的package包/类
public void testToDoubleCoercion() throws Exception
{
    for (int mode : ALL_STREAMING_MODES) {
        JsonParser p;

        // BigDecimal->double
        p = createParser(mode, "100.5");
        assertToken(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
        assertEquals(new BigDecimal("100.5"), p.getDecimalValue());
        assertEquals(100.5, p.getDoubleValue());
        p.close();

        p = createParser(mode, "10");
        assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
        assertEquals(BigInteger.TEN, p.getBigIntegerValue());
        assertEquals(10.0, p.getDoubleValue());
        p.close();
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:NumberCoercionTest.java

示例10: testNextValue

import com.fasterxml.jackson.core.JsonToken; //导入依赖的package包/类
@Test
public void testNextValue() throws IOException {
    IonParser parser = parse("{foo:{bar:\"abc\"}, baz:123} 42.0");
    assertEquals(JsonToken.START_OBJECT, parser.nextValue());
    assertEquals(JsonToken.START_OBJECT, parser.nextValue());
    assertEquals("foo", parser.getCurrentName());
    assertEquals(JsonToken.VALUE_STRING, parser.nextValue());
    assertEquals("abc", parser.getText());
    assertEquals("bar", parser.getCurrentName());
    assertEquals(JsonToken.END_OBJECT, parser.nextValue());
    assertEquals(JsonToken.VALUE_NUMBER_INT, parser.nextValue());
    assertEquals(123, parser.getIntValue());
    assertEquals("baz", parser.getCurrentName());
    assertEquals(JsonToken.END_OBJECT, parser.nextValue());
    assertEquals(JsonToken.VALUE_NUMBER_FLOAT, parser.nextValue());
    assertEquals(42.0, parser.getFloatValue(), 1e-9);
    assertNull(parser.nextValue());
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:19,代码来源:IonParserTest.java

示例11: parse

import com.fasterxml.jackson.core.JsonToken; //导入依赖的package包/类
@Override
public void parse(IonParser parser) throws IOException {
    assertEquals(JsonToken.VALUE_NUMBER_INT, parser.nextToken());
    assertEquals(BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE), parser.getBigIntegerValue());
    try {
        parser.getLongValue();
    } catch (IonException e1) {
        assertEquals(JsonToken.VALUE_NUMBER_INT, parser.nextToken());
        assertEquals(BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.ONE), parser.getBigIntegerValue());
        try {
            parser.getLongValue();
        } catch (IonException e2) {
            return;
        }
    }
    throw new AssertionError("number shouldn't fit in a long");
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:18,代码来源:IonRoundtripTest.java

示例12: objectText

import com.fasterxml.jackson.core.JsonToken; //导入依赖的package包/类
@Override
public Object objectText() throws IOException {
    JsonToken currentToken = parser.getCurrentToken();
    if (currentToken == JsonToken.VALUE_STRING) {
        return text();
    } else if (currentToken == JsonToken.VALUE_NUMBER_INT || currentToken == JsonToken.VALUE_NUMBER_FLOAT) {
        return parser.getNumberValue();
    } else if (currentToken == JsonToken.VALUE_TRUE) {
        return Boolean.TRUE;
    } else if (currentToken == JsonToken.VALUE_FALSE) {
        return Boolean.FALSE;
    } else if (currentToken == JsonToken.VALUE_NULL) {
        return null;
    } else {
        return text();
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:JsonXContentParser.java

示例13: readExtensions

import com.fasterxml.jackson.core.JsonToken; //导入依赖的package包/类
public static <T> List<Extension<T>> readExtensions(JsonParser parser, DeserializationContext context) throws IOException {
    Objects.requireNonNull(parser);
    Objects.requireNonNull(context);

    List<Extension<T>> extensions = new ArrayList<>();

    while (parser.nextToken() != JsonToken.END_OBJECT) {
        String extensionName = parser.getCurrentName();
        ExtensionJson extensionJson = ExtensionSupplier.findExtensionJson(extensionName);
        if (extensionJson != null) {
            parser.nextToken();
            Extension<T> extension = extensionJson.deserialize(parser, context);
            extensions.add(extension);
        } else {
            skip(parser);
        }
    }

    return extensions;
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:21,代码来源:JsonUtil.java

示例14: parse

import com.fasterxml.jackson.core.JsonToken; //导入依赖的package包/类
@Override
public ParentModel parse(JsonParser jsonParser) throws IOException {
    ParentModel instance = new ParentModel();
    if (jsonParser.getCurrentToken() == null) {
        jsonParser.nextToken();
    }
    if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) {
        jsonParser.skipChildren();
        return null;
    }
    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
        String fieldName = jsonParser.getCurrentName();
        jsonParser.nextToken();
        parseField(instance, fieldName, jsonParser);
        jsonParser.skipChildren();
    }
    return instance;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:ParentModel$$JsonObjectMapper.java

示例15: readMockFile

import com.fasterxml.jackson.core.JsonToken; //导入依赖的package包/类
/**
 * Read events mock file, and push it
 *
 * @param dataProducer contains the queue
 * @param mapper       indicates how to parse the file
 * @param parser       contains mocks
 * @param start        time when method is called
 * @return true if interrupted, False if it ended with normal behaviour
 * @see IDataProducer
 */
default boolean readMockFile(IDataProducer dataProducer, ObjectMapper mapper, JsonParser parser, long start) {
    try {
        while (parser.nextToken() == JsonToken.START_OBJECT) {
            ObjectNode objectNode = mapper.readTree(parser);
            Event event = getEventFromJson(objectNode);
            pushIfValidEvent(dataProducer, event, start);
        }
    } catch (IOException e) {
        LOGGER.error("Something went wrong with the facebook post reading");
        return true;
    } finally {
        Thread.currentThread().interrupt();
    }
    return false;
}
 
开发者ID:IKB4Stream,项目名称:IKB4Stream,代码行数:26,代码来源:IProducerConnectorMock.java


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