Skip to content
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

module-info.java does not require java.xml directly #490

Closed
tomsontom opened this issue May 18, 2021 · 5 comments · Fixed by #491
Closed

module-info.java does not require java.xml directly #490

tomsontom opened this issue May 18, 2021 · 5 comments · Fixed by #491

Comments

@tomsontom
Copy link
Contributor

tomsontom commented May 18, 2021

I've tried to use yasson in a project where I also use jlink to build a custom JRE. Looking the at the runtime dependencies of yasson it only requires:

  • jakarta.json
  • jakarta.json.bind
  • java.logging

as the other requires are defined as static. Building an image and launch although leads to the following error

Started application
May 18, 2021 12:53:01 PM org.eclipse.yasson.internal.Marshaller marshall
SCHWERWIEGEND: Generating incomplete JSON
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/datatype/XMLGregorianCalendar
        at [email protected]/org.eclipse.yasson.internal.serializer.DefaultSerializers.initSerializers(DefaultSerializers.java:143)
        at [email protected]/org.eclipse.yasson.internal.serializer.DefaultSerializers.<clinit>(DefaultSerializers.java:57)
        at [email protected]/org.eclipse.yasson.internal.AnnotationIntrospector.collectAnnotations(AnnotationIntrospector.java:763)
        at [email protected]/org.eclipse.yasson.internal.MappingContext.lambda$createParseClassModelFunction$1(MappingContext.java:90)
        at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(Unknown Source)
        at [email protected]/org.eclipse.yasson.internal.MappingContext.getOrCreateClassModel(MappingContext.java:81)
        at [email protected]/org.eclipse.yasson.internal.Marshaller.getRootSerializer(Marshaller.java:161)
        at [email protected]/org.eclipse.yasson.internal.Marshaller.serializeRoot(Marshaller.java:142)
        at [email protected]/org.eclipse.yasson.internal.Marshaller.marshall(Marshaller.java:73)
        at [email protected]/org.eclipse.yasson.internal.Marshaller.marshall(Marshaller.java:101)
        at [email protected]/org.eclipse.yasson.internal.JsonBinding.toJson(JsonBinding.java:126)
....

The problem is caused because java.desktop and java.sql transitively require java.xml so even linking in javax.xml does not help because the yasson module is not going to find the classes in java.xml unless the static module is there.

My current fix is to link in java.desktop - I have no idea why java.sql does not work - but ideally I can get rid of those extra bits.

I tested with a modified module-info.java that adding a requires java.xml fixes the problem.

One could naturally argue now that java.xml should be required static and one would handle the CNF gracefully in DefaultSerializers because if this (de)serializer is used the user anyways has to have him/her self a runtime dependency on java.xml.

I'll provide a PR and this can be discussed there.

@Verdent
Copy link
Member

Verdent commented Jun 8, 2021

Hi Tom,
I do agree that this should be optional similarly to java.sql. Thank you for proposed solution. :-) Could you please change it a bit to register deserializers and serializers of XMLGregorianCalendar similarly to as it is done for java.sql.Date? This allows us to make java,xml static and finally fully optional :-)

@tomsontom
Copy link
Contributor Author

sure - I'll take a look tomorrow and update the PR

@Verdent
Copy link
Member

Verdent commented Jun 8, 2021

Great! Thank you for quick response and sorry for unexcusable delay from my side.

@tomsontom
Copy link
Contributor Author

As I maintain multiple OSS-Projects myself beside the company duties I'm assigned on you don't have to excuse for not directly following up.

@tomsontom
Copy link
Contributor Author

I applied the java.sql strategy and made the java.xml dependency static

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants