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

[REQ] [JAVA] Generation should exit with error when an unsupported serialization library is chosen #18852

Open
Philzen opened this issue Jun 4, 2024 · 0 comments

Comments

@Philzen
Copy link
Contributor

Philzen commented Jun 4, 2024

Is your feature request related to a problem? Please describe.

Related to #18829 – although it is documented in the library option, it would be much more helpful to users if it would fail hard.

Describe the solution you'd like

Ideally, the generator would know about this and exit with a helpful message. Less ideal, it would just throw an exception (might lead to more bug reports than it saves).

Approach

Generally, the current codebase lacks the ability to programmatically query this kind of information from one place. I've started to develop a structured enum that may could be used for this task and also simplify the existing assignment of serializationLibrary in processOpts():

@Getter enum Library {
APACHE_HTTPCLIENT("apache-httpclient", Serializer.JACKSON),
FEIGN("feign", Serializer.JACKSON, Set.of(Serializer.GSON)),
GOOGLE_API_CLIENT("google-api-client", Serializer.JACKSON),
JERSEY_2("jersey2", Serializer.JACKSON),
JERSEY_3("jersey3", Serializer.JACKSON),
MICROPROFILE("microprofile", Serializer.JSONB, Set.of(Serializer.JACKSON)),
NATIVE("native", Serializer.JACKSON),
OKHTTP("okhttp-gson", Serializer.GSON),
REST_ASSURED("rest-assured", Serializer.GSON, Set.of(Serializer.JACKSON)),
RESTEASY("resteasy", Serializer.JACKSON),
REST_CLIENT("restclient", Serializer.JACKSON),
REST_TEMPLATE("resttemplate", Serializer.JACKSON),
RETROFIT_2("retrofit2", Serializer.GSON),
VERTX("vertx", Serializer.JACKSON),
WEBCLIENT("webclient", Serializer.JACKSON);
public final String value;
public final Set<Serializer> supportedSerializers;
public final Serializer defaultSerializer;
Library(String identifier, Serializer defaultSerializer) {
this(identifier, defaultSerializer, Set.of());
}
Library(String identifier, Serializer defaultSerializer, Set<Serializer> otherSupportedSerializers) {
otherSupportedSerializers = new HashSet<>(otherSupportedSerializers);
otherSupportedSerializers.add(defaultSerializer);
this.supportedSerializers = Set.copyOf(otherSupportedSerializers);
this.defaultSerializer = defaultSerializer;
this.value = identifier;
}
}
enum Serializer {
GSON, JACKSON, JSONB;
public String toString() {
return this.name().toLowerCase(Locale.ROOT);
}
}

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

No branches or pull requests

1 participant