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


Java JsonParser.setCodec方法代码示例

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


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

示例1: deserialize

import com.fasterxml.jackson.core.JsonParser; //导入方法依赖的package包/类
@Override
public PrivateKey deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException {
    jsonParser.setCodec(OBJECT_MAPPER);
    JsonNode node = jsonParser.getCodec().readTree(jsonParser);

    try {
        return createPrivateKey(Base64.getDecoder().decode(node.asText()));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:alphagov,项目名称:verify-service-provider,代码行数:12,代码来源:PrivateKeyDeserializer.java

示例2: shouldNotRemoveKnownPublicClaimsFromTree

import com.fasterxml.jackson.core.JsonParser; //导入方法依赖的package包/类
@Test
public void shouldNotRemoveKnownPublicClaimsFromTree() throws Exception {
    String payloadJSON = "{\n" +
            "  \"iss\": \"auth0\",\n" +
            "  \"sub\": \"emails\",\n" +
            "  \"aud\": \"users\",\n" +
            "  \"iat\": 10101010,\n" +
            "  \"exp\": 11111111,\n" +
            "  \"nbf\": 10101011,\n" +
            "  \"jti\": \"idid\",\n" +
            "  \"roles\":\"admin\" \n" +
            "}";
    StringReader reader = new StringReader(payloadJSON);
    JsonParser jsonParser = new JsonFactory().createParser(reader);
    ObjectMapper mapper = new ObjectMapper();
    jsonParser.setCodec(mapper);

    Payload payload = deserializer.deserialize(jsonParser, mapper.getDeserializationContext());

    assertThat(payload, is(notNullValue()));
    assertTrue(payload.getIssuer().contains("auth0"));
    assertTrue(payload.getSubject().contains("emails"));
    assertThat(payload.getAudience(), is(IsCollectionContaining.hasItem("users")));
    assertThat(payload.getIssuedAt().getTime(), is(10101010L * 1000));
    assertThat(payload.getExpiresAt().getTime(), is(11111111L * 1000));
    assertThat(payload.getNotBefore().getTime(), is(10101011L * 1000));
    assertThat(payload.getId(), is("idid"));

    assertThat(payload.getClaim("roles").asString(), is("admin"));
    assertThat(payload.getClaim("iss").asString(), is("auth0"));
    assertThat(payload.getClaim("sub").asString(), is("emails"));
    assertThat(payload.getClaim("aud").asString(), is("users"));
    assertThat(payload.getClaim("iat").asDouble(), is(10101010D));
    assertThat(payload.getClaim("exp").asDouble(), is(11111111D));
    assertThat(payload.getClaim("nbf").asDouble(), is(10101011D));
    assertThat(payload.getClaim("jti").asString(), is("idid"));
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:38,代码来源:PayloadDeserializerTest.java

示例3: shouldNotRemoveKnownPublicClaimsFromTree

import com.fasterxml.jackson.core.JsonParser; //导入方法依赖的package包/类
@Test
public void shouldNotRemoveKnownPublicClaimsFromTree() throws Exception {
    String headerJSON = "{\n" +
            "  \"alg\": \"HS256\",\n" +
            "  \"typ\": \"jws\",\n" +
            "  \"cty\": \"content\",\n" +
            "  \"kid\": \"key\",\n" +
            "  \"roles\": \"admin\"\n" +
            "}";
    StringReader reader = new StringReader(headerJSON);
    JsonParser jsonParser = new JsonFactory().createParser(reader);
    ObjectMapper mapper = new ObjectMapper();
    jsonParser.setCodec(mapper);

    Header header = deserializer.deserialize(jsonParser, mapper.getDeserializationContext());

    assertThat(header, is(notNullValue()));
    assertThat(header.getAlgorithm(), is("HS256"));
    assertThat(header.getType(), is("jws"));
    assertThat(header.getContentType(), is("content"));
    assertThat(header.getKeyId(), is("key"));

    assertThat(header.getHeaderClaim("roles").asString(), is("admin"));
    assertThat(header.getHeaderClaim("alg").asString(), is("HS256"));
    assertThat(header.getHeaderClaim("typ").asString(), is("jws"));
    assertThat(header.getHeaderClaim("cty").asString(), is("content"));
    assertThat(header.getHeaderClaim("kid").asString(), is("key"));
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:29,代码来源:HeaderDeserializerTest.java


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