private static DeserializerFactoryConfig getDeserializerFactoryConfig(ObjectMapper objectMapper) { return ((BasicDeserializerFactory) objectMapper.getDeserializationContext().getFactory()).getFactoryConfig(); }
private static DeserializerFactoryConfig getDeserializerFactoryConfig(ObjectMapper objectMapper) { return ((BasicDeserializerFactory) objectMapper.getDeserializationContext().getFactory()).getFactoryConfig(); }
public static synchronized void reset() { for (ObjectMapper mapper : U.list(MAPPER, PRETTY_MAPPER)) { SerializerProvider serializerProvider = mapper.getSerializerProvider(); if (serializerProvider instanceof DefaultSerializerProvider) { DefaultSerializerProvider provider = (DefaultSerializerProvider) serializerProvider; provider.flushCachedSerializers(); } else { Log.warn("Couldn't clear the cache of Jackson serializers!", "class", Cls.of(serializerProvider)); } DeserializationContext deserializationContext = mapper.getDeserializationContext(); Object cache = Cls.getFieldValue(deserializationContext, "_cache"); if (cache instanceof DeserializerCache) { DeserializerCache deserializerCache = (DeserializerCache) cache; deserializerCache.flushCachedDeserializers(); } else { Log.warn("Couldn't clear the cache of Jackson deserializers!", "class", Cls.of(cache)); } } }
@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")); }
jsonParser.setCodec(mapper); Payload payload = deserializer.deserialize(jsonParser, mapper.getDeserializationContext());
public AbstractTypeCustomizationFactory(ObjectMapper mapper) { this.serializerProvider = mapper.getSerializerProviderInstance(); this.serializerFactory = (CustomBeanSerializerFactory) mapper.getSerializerFactory(); this.typeFactory = mapper.getTypeFactory(); this.deserializationContext = mapper.getDeserializationContext(); this.deserializationConfig = mapper.getDeserializationConfig(); }
public EUMSpan performDeserialization(ObjectNode nodeToParse) throws IOException { String json = nodeToParse.toString(); InputStream stream = new ByteArrayInputStream(json.getBytes()); ObjectMapper mapper = new ObjectMapper(); JsonParser parser = mapper.getFactory().createParser(stream); DeserializationContext ctxt = mapper.getDeserializationContext(); return deserializer.deserialize(parser, ctxt); }
private AnnotatedType resolveDeserializableType(Annotated accessor, AnnotatedType realType, JavaType baseType, ObjectMapper objectMapper) { AnnotationIntrospector introspector = objectMapper.getDeserializationConfig().getAnnotationIntrospector(); try { objectMapper.getDeserializationContext().getFactory().mapAbstractType(objectMapper.getDeserializationConfig(), objectMapper.constructType(Map.class)); JavaType refined = introspector.refineDeserializationType(objectMapper.getDeserializationConfig(), accessor, baseType); Class<?> raw = ClassUtils.getRawType(realType.getType()); if (!refined.getRawClass().equals(raw)) { if (GenericTypeReflector.isSuperType(realType.getType(), refined.getRawClass())) { AnnotatedType candidate = GenericTypeReflector.getExactSubType(realType, refined.getRawClass()); if (!ClassUtils.isMissingTypeParameters(candidate.getType())) { return candidate; } } return GenericTypeReflector.updateAnnotations(TypeUtils.toJavaType(refined), realType.getAnnotations()); } } catch (JsonMappingException e) { /*no-op*/ } catch (Exception e) { log.warn("Failed to determine the deserializable type for " + GenericTypeReflector.getTypeName(realType.getType()) + " due to an exception", e); } return realType; }