-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correct retrieving deserializer / serializer from the bean context #859
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,11 +25,14 @@ | |
import io.micronaut.core.type.Argument; | ||
import io.micronaut.inject.ArgumentInjectionPoint; | ||
import io.micronaut.inject.InjectionPoint; | ||
import io.micronaut.serde.Deserializer; | ||
import io.micronaut.serde.Serde; | ||
import io.micronaut.serde.SerdeIntrospections; | ||
import io.micronaut.serde.Serializer; | ||
import io.micronaut.serde.config.DeserializationConfiguration; | ||
import io.micronaut.serde.config.SerdeConfiguration; | ||
import io.micronaut.serde.config.SerializationConfiguration; | ||
import io.micronaut.serde.exceptions.SerdeException; | ||
import io.micronaut.serde.support.deserializers.ObjectDeserializer; | ||
import io.micronaut.serde.support.deserializers.SerdeDeserializationPreInstantiateCallback; | ||
import io.micronaut.serde.support.serdes.InetAddressSerde; | ||
|
@@ -69,6 +72,32 @@ <S extends Serde<T>, T> S provideSerde(InjectionPoint<Serde<T>> serdeInjectionPo | |
return null; | ||
} | ||
|
||
@Any | ||
@Prototype | ||
@BootstrapContextCompatible | ||
<S extends Deserializer<T>, T> S provideDeserializer(InjectionPoint<Deserializer<T>> injectionPoint, | ||
BeanProvider<DefaultSerdeRegistry> serdeRegistry) throws SerdeException { | ||
if (injectionPoint instanceof ArgumentInjectionPoint<?, ?> argumentInjectionPoint) { | ||
Argument typeParameter = argumentInjectionPoint.getArgument().getTypeParameters()[0]; | ||
DefaultSerdeRegistry defaultSerdeRegistry = serdeRegistry.get(); | ||
return (S) defaultSerdeRegistry.findDeserializer(typeParameter); | ||
} | ||
return null; | ||
} | ||
|
||
@Any | ||
@Prototype | ||
@BootstrapContextCompatible | ||
<S extends Serializer<T>, T> S provideSerializer(InjectionPoint<Serializer<T>> injectionPoint, | ||
BeanProvider<DefaultSerdeRegistry> serdeRegistry) throws SerdeException { | ||
if (injectionPoint instanceof ArgumentInjectionPoint<?, ?> argumentInjectionPoint) { | ||
Argument typeParameter = argumentInjectionPoint.getArgument().getTypeParameters()[0]; | ||
DefaultSerdeRegistry defaultSerdeRegistry = serdeRegistry.get(); | ||
return (S) defaultSerdeRegistry.findSerializer(typeParameter); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does it need a call to |
||
} | ||
return null; | ||
} | ||
|
||
@Singleton | ||
@BootstrapContextCompatible | ||
ObjectSerializer provideObjectSerializer(BeanContext beanContext, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ package io.micronaut.serde.support.serdes | |
|
||
import io.micronaut.context.BeanContext | ||
import io.micronaut.core.type.Argument | ||
import io.micronaut.serde.Deserializer | ||
import io.micronaut.serde.Serde | ||
import io.micronaut.serde.Serializer | ||
import io.micronaut.serde.support.deserializers.ObjectDeserializer | ||
import io.micronaut.serde.support.serializers.ObjectSerializer | ||
import io.micronaut.test.extensions.spock.annotation.MicronautTest | ||
|
@@ -71,5 +73,21 @@ class BeanContextSerdeSpec extends Specification { | |
enumSerde.getClass() == EnumSerde | ||
} | ||
|
||
void "test retrieving Map deserializer"() { | ||
when: | ||
def deserializer = beanContext.getBean(Argument.of(Deserializer, Argument.mapOf(String, Object))) | ||
|
||
then: | ||
deserializer | ||
} | ||
|
||
void "test retrieving Map serializer"() { | ||
when: | ||
def deserializer = beanContext.getBean(Argument.of(Serializer, Argument.mapOf(String, Object))) | ||
|
||
then: | ||
deserializer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add tests that actually use the serialiser/deserializer to serialize There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
} | ||
|
||
static enum MyEnum {} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it need a call to createSpecific?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes