-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Allow schema and validation event handler customization in JAXBContextFactory #2084
Allow schema and validation event handler customization in JAXBContextFactory #2084
Conversation
@@ -51,6 +78,10 @@ public Unmarshaller createUnmarshaller(Class<?> clazz) throws JAXBException { | |||
public Marshaller createMarshaller(Class<?> clazz) throws JAXBException { | |||
Marshaller marshaller = getContext(clazz).createMarshaller(); | |||
setMarshallerProperties(marshaller); | |||
if (marshallerEventHandler != null) { |
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.
So, this is piling more and more functionality/code into feign to allow fine tuning... wonder if it would be possible to turn this into an interface that allows user to do whatever they to JAXBContext
and pass it to feign in a more transparent way..
JAXBContextFactory is IMO a misnomer, as it's mainly used to create
Marshaller and Unmarshaller instances - things that actually do the
serialization and deserialization. The contexts are also created, but are
cached per class, and usually an application can have a single context for
all supported classes if there's no package/namespace collisions.
But JAXBContext once created isn't very customizable by itself and I don't
see a way to achieve the needed fine-tuning unless we do some subclassing
hackery and delegate to the real thing from Glassfish or your favorite JAXB
provider. This is IMO much more fragile than the solution proposed here.
That said we can actually create some sort of MarshallerCustomizer /
UnmarshallerCustomizer interface that does the needed post-processing. We
may even wrap the already implemented property setters as instances of such
customizers and execute them in sequential order like done for request
interceptors.
How's that sound?
…On Tue, Jun 20, 2023, 00:02 Marvin Froeder ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In jaxb-jakarta/src/main/java/feign/jaxb/JAXBContextFactory.java
<#2084 (comment)>:
> @@ -51,6 +78,10 @@ public Unmarshaller createUnmarshaller(Class<?> clazz) throws JAXBException {
public Marshaller createMarshaller(Class<?> clazz) throws JAXBException {
Marshaller marshaller = getContext(clazz).createMarshaller();
setMarshallerProperties(marshaller);
+ if (marshallerEventHandler != null) {
So, this is piling more and more functionality/code into feign to allow
fine tuning... wonder if it would be possible to turn this into an
interface that allows user to do whatever they to JAXBContext and pass it
to feign in a more transparent way..
—
Reply to this email directly, view it on GitHub
<#2084 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOF63JBEN7UXCHZVDZ4EOTXMC46BANCNFSM6AAAAAAZGNVESQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
sounds great, would avoid all ifs inside feign, if you keen to do it, I would like to see it |
The default JAXB behavior is to silently ignore errors caused by input being incorrect, so eg. an
Integer
field will remainnull
for an inputfoo
. This isn't always preferred, but to fix that aValidationEventHandler
implementation must be assigned to the createdUnmarshaller
. It may be as simple asevent -> false
.For a more complex validation scenario a
Schema
may be needed.However at the moment there is no way to set up either of those in
Marshaller
andUnmarshaller
instances created in JAXB and SOAP encoders/decoders.The PR addresses this problem by adding the customization options for
feign.jaxb.JAXBContextFactory
injaxb
andjaxb-jakarta
modules. A customizedJAXBContextFactory
may then be used to address the original issue in #1479 .