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