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 as Object issues #140

Closed
haynesgt opened this issue May 3, 2017 · 6 comments
Closed

Enum as Object issues #140

haynesgt opened this issue May 3, 2017 · 6 comments

Comments

@haynesgt
Copy link

haynesgt commented May 3, 2017

I have enums that are annotated with @JsonFormat(shape= JsonFormat.Shape.OBJECT

My enums are like this:

@JsonFormat(shape= JsonFormat.Shape.OBJECT)
public enum StatusType {
        GOOD(0, "Good"),
        FULL(1, "Full");
        private int code;
        private String label;
        private StatusType(int code, String label) {
            this.label = label;
            this.code = code;
        }
	public int getCode() { return code; }
	public String getLabel() { return label; }
}

In the HTTP response they look like this:

{
    code: 0,
    label: "GOOD"
}

However, my generated Typescript looks like this:

    export type StatusType = "GOOD" | "FULL";

Also, excluding the class does not work. StatusType is still there.

I'm looking for a workaround right now.

@vojtechhabarta
Copy link
Owner

Universal workaround is to exclude class which is not mapped correctly. Excluded class is then mapped to any.

I am not sure why excluding doesn't work in your case. I added test(eed856e) specifically for enum class and it works.

@haynesgt
Copy link
Author

haynesgt commented May 4, 2017

sorry -- I was using 1.24.314 but fix is in 1.24.320

@vojtechhabarta
Copy link
Owner

Build v1.24.320 adds just one test and it is not released to maven central repository.
Anyway, does it mean that exclude workaround now works for you?

@vojtechhabarta
Copy link
Owner

I implemented support for enums with JsonFormat.Shape.OBJECT (release 1.25.322).
Could you please try it?

@haynesgt
Copy link
Author

It works!

@vojtechhabarta
Copy link
Owner

Closing old issues after release.

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