本文整理汇总了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);
}
}
示例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"));
}
示例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"));
}