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


Java JsonParser類代碼示例

本文整理匯總了Java中com.fasterxml.jackson.core.JsonParser的典型用法代碼示例。如果您正苦於以下問題:Java JsonParser類的具體用法?Java JsonParser怎麽用?Java JsonParser使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JsonParser類屬於com.fasterxml.jackson.core包,在下文中一共展示了JsonParser類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入依賴的package包/類
@Override public AnInterface deserialize(JsonParser jp, DeserializationContext ctxt)
    throws IOException {
  if (jp.getCurrentToken() != JsonToken.START_OBJECT) {
    throw new AssertionError("Expected start object.");
  }

  String name = null;

  while (jp.nextToken() != JsonToken.END_OBJECT) {
    switch (jp.getCurrentName()) {
      case "name":
        name = jp.getValueAsString();
        break;
    }
  }

  return new AnImplementation(name);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:JacksonConverterFactoryTest.java

示例3: parseInputArrayOfStrings

import com.fasterxml.jackson.core.JsonParser; //導入依賴的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

示例4: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入依賴的package包/類
public static RegisterMessage deserialize(JsonParser jp) throws IOException {
	jp.nextToken();
	long request = jp.getLongValue();

	boolean discloseCaller = false;
	jp.nextToken();
	Map<String, Object> options = ParserUtil.readObject(jp);
	if (options != null) {
		discloseCaller = (boolean) options.getOrDefault("disclose_caller", false);
	}

	jp.nextToken();
	String procedure = jp.getValueAsString();

	return new RegisterMessage(request, procedure, discloseCaller);
}
 
開發者ID:ralscha,項目名稱:wamp2spring,代碼行數:17,代碼來源:RegisterMessage.java

示例5: testSkipChildren

import com.fasterxml.jackson.core.JsonParser; //導入依賴的package包/類
@Test
public void testSkipChildren() throws IOException {
    JsonParser[] jsonParserArray = new JsonParser[3];
    IOContext ioContext = new IOContext(new BufferRecycler(), jsonParserArray, true);
    byte[] byteArray = new byte[8];
    InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray, 0, (byte) 58);
    UTF8StreamJsonParser uTF8StreamJsonParser = new UTF8StreamJsonParser(ObjectReadContext.empty(),
            ioContext,
            0, byteArrayInputStream, ByteQuadsCanonicalizer.createRoot(),
            byteArray, -1, (byte) 9, true);
    JsonParserDelegate jsonParserDelegate = new JsonParserDelegate(jsonParserArray[0]);
    JsonParserSequence jsonParserSequence = JsonParserSequence.createFlattened(true, uTF8StreamJsonParser, jsonParserDelegate);
    JsonParserSequence jsonParserSequenceTwo = (JsonParserSequence) jsonParserSequence.skipChildren();

    assertEquals(2, jsonParserSequenceTwo.containedParsersCount());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:JsonParserSequenceTest.java

示例6: jsonToColumnValue

import com.fasterxml.jackson.core.JsonParser; //導入依賴的package包/類
@Override
public Value jsonToColumnValue(JsonParser parser, ValueMetadata metadata) throws IOException {
    JsonToken token;
    Value value;

    // Go to the next token
    token = parser.nextToken();

    if (token != JsonToken.VALUE_STRING && token != JsonToken.VALUE_NULL) {
        throw new IOException("Unable to parse field " + metadata.getName() + " expected string or null at line " + parser.getCurrentLocation().getLineNr());
    }

    // Can be a integer or null
    if (token == JsonToken.VALUE_STRING) {
        value = new Value(parser.getValueAsString(), metadata);
    } else {
        // null
        if (metadata.isNotNull()) {
            throw new IOException("Unable to parse field " + metadata.getName() + " expected string but found null at line " + parser.getCurrentLocation().getLineNr());
        }

        value = new Value(metadata);
    }

    return value;
}
 
開發者ID:claudiodegio,項目名稱:dbsync,代碼行數:27,代碼來源:JSonStringConverter.java

示例7: configureFeature

import com.fasterxml.jackson.core.JsonParser; //導入依賴的package包/類
private void configureFeature(Object feature, boolean enabled) {
	if (feature instanceof JsonParser.Feature) {
		this.objectMapper.configure((JsonParser.Feature) feature, enabled);
	}
	else if (feature instanceof JsonGenerator.Feature) {
		this.objectMapper.configure((JsonGenerator.Feature) feature, enabled);
	}
	else if (feature instanceof SerializationFeature) {
		this.objectMapper.configure((SerializationFeature) feature, enabled);
	}
	else if (feature instanceof DeserializationFeature) {
		this.objectMapper.configure((DeserializationFeature) feature, enabled);
	}
	else if (feature instanceof MapperFeature) {
		this.objectMapper.configure((MapperFeature) feature, enabled);
	}
	else {
		throw new FatalBeanException("Unknown feature class: " + feature.getClass().getName());
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:Jackson2ObjectMapperFactoryBean.java

示例8: merge

import com.fasterxml.jackson.core.JsonParser; //導入依賴的package包/類
/**
 * Parse a text-format message from {@code input} and merge the contents into {@code builder}.
 * Extensions will be recognized if they are registered in {@code extensionRegistry}.
 * @throws IOException
 */
public void merge(JsonParser parser,
						 ExtensionRegistry extensionRegistry,
                         Message.Builder builder) throws IOException {

    JsonToken token = parser.nextToken();
    if (token.equals(JsonToken.START_OBJECT)) {
    	token = parser.nextToken();
    }
    while (token != null && !token.equals(JsonToken.END_OBJECT)) {
    	mergeField(parser, extensionRegistry, builder);
    	token = parser.nextToken();
    }

    // Test to make sure the tokenizer has reached the end of the stream.
    if (parser.nextToken() != null) {
        throw new RuntimeException("Expecting the end of the stream, but there seems to be more data!  Check the input for a valid JSON format.");
    }
}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:24,代碼來源:JsonJacksonFormat.java

示例9: parse

import com.fasterxml.jackson.core.JsonParser; //導入依賴的package包/類
@Override
public NonPrivateFieldsAndAccessorsFieldDetectionPolicyModel parse(JsonParser jsonParser) throws IOException {
    NonPrivateFieldsAndAccessorsFieldDetectionPolicyModel instance = new NonPrivateFieldsAndAccessorsFieldDetectionPolicyModel();
    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,代碼來源:NonPrivateFieldsAndAccessorsFieldDetectionPolicyModel$$JsonObjectMapper.java

示例10: parse

import com.fasterxml.jackson.core.JsonParser; //導入依賴的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

示例11: getValueFromFieldType

import com.fasterxml.jackson.core.JsonParser; //導入依賴的package包/類
public static Object getValueFromFieldType(JsonParser parser, MinorType fieldType) throws IOException {
  switch (fieldType) {
    case BIGINT:
      return parser.getLongValue();
    case VARCHAR:
      return parser.getValueAsString();
    case FLOAT4:
      return parser.getFloatValue();
    case BIT:
      return parser.getBooleanValue();
    case LATE:
    case NULL:
      return null;
    default:
      throw new RuntimeException("Unexpected Field type to return value: " + fieldType.toString());
  }
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:18,代碼來源:JacksonHelper.java

示例12: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入依賴的package包/類
@Override
public LocalDateTime deserialize(JsonParser parser, DeserializationContext context) throws IOException
{
    if (parser.hasTokenId(JsonTokenId.ID_STRING)) {
        String string = parser.getText().trim();
        if (string.length() == 0) {
            return null;
        }
        
        try {
            return LocalDateTime.parse(string, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
        } catch (DateTimeException e) {
            throw new IOException(e);
        }
    }
    if (parser.hasTokenId(JsonTokenId.ID_EMBEDDED_OBJECT)) {
        return (LocalDateTime) parser.getEmbeddedObject();
    }
    throw context.wrongTokenException(parser, JsonToken.VALUE_STRING, "Expected string.");
}
 
開發者ID:kiegroup,項目名稱:optashift-employee-rostering,代碼行數:21,代碼來源:LocalDateTimeDeserializer.java

示例13: parse

import com.fasterxml.jackson.core.JsonParser; //導入依賴的package包/類
@Override
public PrivateFieldModel parse(JsonParser jsonParser) throws IOException {
    PrivateFieldModel instance = new PrivateFieldModel();
    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,代碼來源:PrivateFieldModel$$JsonObjectMapper.java

示例14: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入依賴的package包/類
public static UnsubscribedMessage deserialize(JsonParser jp) throws IOException {
	jp.nextToken();
	long request = jp.getLongValue();

	Long subscriptionId = null;
	String reason = null;

	JsonToken token = jp.nextToken();
	if (token == JsonToken.START_OBJECT) {
		Map<String, Object> details = ParserUtil.readObject(jp);
		reason = (String) details.get("reason");

		Object subscriptionObj = details.get("subscription");
		if (subscriptionObj != null) {
			subscriptionId = ((Number) subscriptionObj).longValue();
		}
	}

	return new UnsubscribedMessage(request, subscriptionId, reason);
}
 
開發者ID:ralscha,項目名稱:wamp2spring,代碼行數:21,代碼來源:UnsubscribedMessage.java

示例15: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入依賴的package包/類
@Override
public Date deserialize(JsonParser gen, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    String date = gen.getText();

    if (StringUtils.isEmpty(date)) {
        return null;
    }

    if (StringUtils.isNumeric(date)) {
        return new Date(Long.valueOf(date));
    }
    try {
        DateTime dt = fmt.parseDateTime(date);
        return dt.toDate();
    } catch (Exception e) {
        throw new IOException(e);
    }
}
 
開發者ID:linuer,項目名稱:nan,代碼行數:19,代碼來源:FDateJsonDeserializer.java


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