本文整理匯總了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"));
}