use of io.micronaut.serde.support.deserializers.ObjectDeserializer in project micronaut-serialization by micronaut-projects.
the class DefaultSerdeRegistry method findDeserializer.
@Override
public <T> Deserializer<? extends T> findDeserializer(Argument<? extends T> type) {
Objects.requireNonNull(type, "Type cannot be null");
final TypeKey key = new TypeKey(type);
final Deserializer<?> deserializer = deserializerMap.get(key);
if (deserializer != null) {
return (Deserializer<? extends T>) deserializer;
} else {
final Argument<Deserializer> deserializerArgument = Argument.of(Deserializer.class, type);
final Collection<BeanRegistration<Deserializer>> beanRegistrations = beanContext.getBeanRegistrations(deserializerArgument, null);
Deserializer<?> deser = null;
if (beanRegistrations.size() == 1) {
deser = beanRegistrations.iterator().next().bean();
} else if (!beanRegistrations.isEmpty()) {
final List<BeanRegistration<Deserializer>> results = beanRegistrations.stream().filter((r) -> {
final Class<?>[] typeParameters = r.getBeanDefinition().getTypeParameters(Deserializer.class);
return typeParameters.length == 1 && typeParameters[0].equals(type.getType());
}).collect(Collectors.toList());
if (results.size() == 1) {
deser = results.iterator().next().bean();
} else {
deser = beanContext.findBean(deserializerArgument).orElse(null);
}
}
if (deser != null) {
deserializerMap.put(key, deser);
return (Deserializer<? extends T>) deser;
}
}
if (key.getType().isArray()) {
deserializerMap.put(key, objectArraySerde);
return (Deserializer<? extends T>) objectArraySerde;
} else {
deserializerMap.put(key, objectDeserializer);
return (Deserializer<? extends T>) objectDeserializer;
}
}
Aggregations