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 to provide custom configuration for JAXB context #25801
Conversation
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.
Thanks for this!
I added an initial round of comments
extensions/jaxb/deployment/src/main/java/io/quarkus/jaxb/deployment/JaxbProcessor.java
Outdated
Show resolved
Hide resolved
extensions/jaxb/runtime/src/main/java/io/quarkus/jaxb/runtime/JaxbContextConfigRecorder.java
Outdated
Show resolved
Hide resolved
099b211
to
362f9d8
Compare
Many thanks! |
Great! I'll take another look later. |
54e1f05
to
35116c9
Compare
This comment has been minimized.
This comment has been minimized.
35116c9
to
b013521
Compare
.../jaxb/deployment/src/main/java/io/quarkus/jaxb/deployment/JaxbClassesToBeBoundBuildItem.java
Outdated
Show resolved
Hide resolved
extensions/jaxb/deployment/src/main/java/io/quarkus/jaxb/deployment/JaxbProcessor.java
Outdated
Show resolved
Hide resolved
extensions/jaxb/deployment/src/main/java/io/quarkus/jaxb/deployment/JaxbProcessor.java
Outdated
Show resolved
Hide resolved
.../jaxb/deployment/src/main/java/io/quarkus/jaxb/deployment/JaxbClassesToBeBoundBuildItem.java
Outdated
Show resolved
Hide resolved
I like the idea, we should mark this as a noteworthy feature |
10b477f
to
4393e39
Compare
extensions/jaxb/runtime/src/main/java/io/quarkus/jaxb/runtime/JaxbContextConfigRecorder.java
Outdated
Show resolved
Hide resolved
4393e39
to
341aa61
Compare
extensions/jaxb/runtime/src/main/java/io/quarkus/jaxb/runtime/JaxbContextProducer.java
Outdated
Show resolved
Hide resolved
2440a9e
to
4d2057c
Compare
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.
LGTM
Apparently the build is failing:
|
4d2057c
to
bf75a60
Compare
This comment has been minimized.
This comment has been minimized.
bf75a60
to
63bb18c
Compare
Yep... This is a sneaky test... It could not reproduce it locally, so I'm adding traces just to see what is going on. |
This comment has been minimized.
This comment has been minimized.
898b20b
to
8cbeb80
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1b90462
to
eb071c3
Compare
This comment has been minimized.
This comment has been minimized.
Maybe it was failing due to some other inconsistencies, but now it seems to be working all the time. |
==== Advanced JAXB-specific features When using the `quarkus-resteasy-reactive-jaxb` extension there are some advanced features that RESTEasy Reactive supports. ===== Inject JAXB components The JAXB resteasy reactive extension will serialize and unserialize requests and responses transparently for users. However, if you need finer usage of the JAXB components, you can inject either the JAXBContext, Marshaller, or Unmarshaller components into your beans: [source,java] ---- @ApplicationScoped public class MyService { @Inject JAXBContext jaxbContext; @Inject Marshaller marshaller; @Inject Unmarshaller unmarshaller; // ... } ---- [NOTE] ==== Quarkus will automatically register all the classes annotated with `@XmlRootElement` to the JAXB context. ==== ===== Customize the JAXB configuration To customize the JAXB configuration for either the JAXB context, and/or the Marshaller/Unmarshaller components, the suggested approach is to define a CDI bean of type `io.quarkus.jaxb.runtime.JaxbContextCustomizer`. An example where a custom module needs to be registered would look like so: [source,java] ---- @singleton public class RegisterCustomModuleCustomizer implements JaxbContextCustomizer { // For JAXB context configuration @OverRide public void customizeContextProperties(Map<String, Object> properties) { } // For Marshaller configuration @OverRide public void customizeMarshaller(Marshaller marshaller) throws PropertyException { marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE); } // For Unmarshaller configuration @OverRide public void customizeUnmarshaller(Unmarshaller unmarshaller) throws PropertyException { // ... } } ---- [NOTE] ==== It's not necessary to implement the three methods, but only the want you need. ==== Alternatively, you can provide your own `JAXBContext` bean by doing: [source,java] ---- public class CustomJaxbContext { // Replaces the CDI producer for JAXBContext built into Quarkus @singleton JAXBContext jaxbContext() { // ... } } ---- [IMPORTANT] ==== By replacing the JAXB context, you need to bound the classes to be serialized/unserialized and also configure the JAXB context accordingly. ====
d3cf78f
to
e812d24
Compare
So is this ready or not? |
Hi! How about to provide a way to disable this feature via configuration? Or maybe separate it from core jaxb support in additional jar? Point is that someone (as I, for example) may have it's own code producing JAXBContext which may (or may not) conflict with this feature. Second point is injecting Marshaller/Unmarshaller in @ApplicationScoped beans may result in errors because Marshaller/Unmarshaller are not thread safe. I mean this feature is something beyond jaxb support for GraalVM and there is no just one right way to configure JAXBContext. |
The
@Sgitario I think we need to make these beans |
#26231 should make the necessary changes |
The REST Client Reactive JAXB was still using the `JAXB.marshall` / `JAXB.unmarshall` utilities that not allow users providing custom JAXB configuration. This change is related to quarkusio#25801 where it was done for the Resteasy Reactive JAXB extension.
Changes added as part of this pull request:
When using the
quarkus-resteasy-reactive-jaxb
extension there are some advanced features that RESTEasy Reactive supports.The JAXB resteasy reactive extension will serialize and deserialize requests and responses transparently for users. However, if you need finer usage of the JAXB components, you can inject either the JAXBContext, Marshaller, or Unmarshaller components into your beans:
Note: Quarkus will automatically register all the classes annotated with
@XmlRootElement
to the JAXB context.To customize the JAXB configuration for either the JAXB context, and/or the Marshaller/Unmarshaller components, the suggested approach is to define a CDI bean of type
io.quarkus.jaxb.runtime.JaxbContextCustomizer
.An example where a custom module needs to be registered would look like so:
Note: It's not necessary to implement the three methods, but only the want you need.
Alternatively, you can provide your own
JAXBContext
bean by doing:Note: By replacing the JAXB context, you need to bound the classes to be serialized/deserialized and also configure the JAXB context accordingly.
Resolves #25753