Skip to content

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

Open
@Philzen

Description

@Philzen

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);
}
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions