We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
The custom Deserializer method not able to handle null value for enum and throwing below exception
JsonParser#getString() is valid only for KEY_NAME, VALUE_STRING, VALUE_NUMBER parser states. But current parser state is VALUE_NULL
Using Open openapi-generator-maven-plugin v7.11.0 with below configuration:
<plugin> <groupId>org.openapitools</groupId> <artifactId>openapi-generator-maven-plugin</artifactId> <version>7.11.0.0</version> <configuration> <addCompileSourceRoot>true</addCompileSourceRoot> <configOptions> <useJakartaEe>true</useJakartaEe> <microprofileRestClientVersion>3.0</microprofileRestClientVersion> <modelNullable>true</modelNullable> <prependFormOrBodyParameters>true</prependFormOrBodyParameters> <serializableModel>false</serializableModel> <dateLibrary>java8</dateLibrary> <java17>true</java17> <useOptionalForEnumFromValue>true</useOptionalForEnumFromValue> <openApiNullable>false</openApiNullable> </configOptions> </configuration>
Below is the enum definiton in openapi.yaml .
division: type: string enum: - PC example: PC
and its generate enum class as below
@JsonbTypeSerializer(DivisionEnum.Serializer.class) @JsonbTypeDeserializer(DivisionEnum.Deserializer.class) public enum DivisionEnum {
PC(String.valueOf("pc")); String value; DivisionEnum (String v) { value = v; } public String value() { return value; } @Override public String toString() { return String.valueOf(value); } public static Optional<DivisionEnum> fromValue(String v) { for (DivisionEnum b : DivisionEnum.values()) { if (String.valueOf(b.value).equals(v)) { return Optional.of(b); } } return Optional.empty(); } public static final class Deserializer implements JsonbDeserializer<DivisionEnum> { @Override public DivisionEnum deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) { for (DivisionEnum b : DivisionEnum.values()) { if (String.valueOf(b.value).equals(parser.getString())) { return b; } } throw new IllegalArgumentException("Unexpected value '" + parser.getString() + "'"); } } public static final class Serializer implements JsonbSerializer<DivisionEnum> { @Override public void serialize(DivisionEnum obj, JsonGenerator generator, SerializationContext ctx) { generator.write(obj.value); } }
parser.getString() throwing below error when enum value is null.
Note: Using jakarta 10 and java 17
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Bug Report Checklist
The custom Deserializer method not able to handle null value for enum and throwing below exception
JsonParser#getString() is valid only for KEY_NAME, VALUE_STRING, VALUE_NUMBER parser states. But current parser state is VALUE_NULL
Using Open openapi-generator-maven-plugin v7.11.0 with below configuration:
Below is the enum definiton in openapi.yaml .
and its generate enum class as below
@JsonbTypeSerializer(DivisionEnum.Serializer.class)
@JsonbTypeDeserializer(DivisionEnum.Deserializer.class)
public enum DivisionEnum {
parser.getString() throwing below error when enum value is null.
JsonParser#getString() is valid only for KEY_NAME, VALUE_STRING, VALUE_NUMBER parser states. But current parser state is VALUE_NULL
Note: Using jakarta 10 and java 17
The text was updated successfully, but these errors were encountered: