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

Provide a separate annotation for registering classes for serialization #20300

Open
zakkak opened this issue Sep 21, 2021 · 3 comments
Open

Provide a separate annotation for registering classes for serialization #20300

zakkak opened this issue Sep 21, 2021 · 3 comments
Labels
kind/enhancement New feature or request

Comments

@zakkak
Copy link
Contributor

zakkak commented Sep 21, 2021

Description

As discussed in #20167 (comment) the use of @RegisterForReflection(targets = String.class, serialization = true) is a bit confusing since it doesn't make clear whether the corresponding class should also be registered for reflection in general (right now it does not).

At the moment it's also not clear how to register a class for both reflection and serialization. Would

@RegisterForReflection(targets = String.class)
public class ReflectionConfig { }

@RegisterForReflection(targets = String.class, serialization = true)
public class SerializationConfig { }

do the trick in such cases?

As a result this feature request is about providing a cleaner interface (through a new annotation) to the end users for registering classes for reflection, serialization, or both.

Implementation ideas

As proposed by @vsevel it looks like a better approach would be to use a new annotation (instead of parameterizing RegisterForReflection).

Then to register a class for both reflection and serialization one should do the following:

@RegisterForReflection
@RegisterForSerialization
public class MyClass {
}

or

@RegisterForReflection(targets = String.class)
@RegisterForSerialization(targets = String.class)
public class ReflectionConfig { }
@Sanne
Copy link
Member

Sanne commented Sep 22, 2021

Not sure if it should be a separate issue, but I'd also love it if we could tune the API of @RegisterForReflection to strongly encourage adding a conditional tied to code reachability - perhaps it should be a required attribute of the annotation?

I understand that making it required would make it a lot of work to migrate to the new annotation, but a good compromise would be to have a default conditional which signals "I haven't thought of this yet"; this could be a placeholder, and we could deprecate it already to discourage excessive use, especially discourage in new code.

@zakkak
Copy link
Contributor Author

zakkak commented Sep 22, 2021

+1 that will also be in line with the new "Conditional Configuration" that is coming in GraalVM 21.3

I think, however, that this should be in a separate feature request :)

@Sanne
Copy link
Member

Sanne commented Sep 22, 2021

Ok for a separate feature request: opened #20331

but if we change the API let's try to do it only once and address both aspects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants