當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。