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

Enum JsonCreator without mode=DELEGATING failed when using jackson >= 2.11 #11740

Open
cksiow opened this issue Mar 16, 2022 · 1 comment
Open

Comments

@cksiow
Copy link

cksiow commented Mar 16, 2022

Description

Currently when we have enum class generated, Deserialize will failed, error:
threw exception [Request processing failed; nested exception is feign.codec.DecodeException: Error while extracting response for type [x.y.z.a.b.c.class] and content type [application/vnd.x.y.z.v1+json]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Input mismatch reading Enum x.y.z.a.b.c.enum: properties-based @JsonCreator ([method x.y.z.a.b.c.enum#fromValue(class name)]) expects JSON Object (JsonToken.START_OBJECT), got JsonToken.VALUE_STRING; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Input mismatch reading Enum x.y.z.a.b.c.enum: properties-based @JsonCreator ([method x.y.z.a.b.c.enum#fromValue(x.y.z.a.b.c.enum)]) expects JSON Object (JsonToken.START_OBJECT), got JsonToken.VALUE_STRING

this one can refer to FasterXML/jackson-module-kotlin#336

Swagger-codegen version

3.0.25

Swagger declaration file content or url
Command line used for generation
Steps to reproduce

any class that contain enum and called Deserialize error will throw

Related issues/PRs
Suggest a fix/enhancement

the simple fix will be change the mustache
https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/Java/modelEnum.mustache
change
{{#jackson}}
@JsonCreator
{{/jackson}}
public static {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}
.......
to
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
{{/jackson}}
public static {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}

@krishnareddyAdamala03
Copy link

Having same issue in my tests

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

No branches or pull requests

2 participants