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 with abstract method throw java.lang.UnsupportedOperationException: Class class com.cloud.thales.infrast.persist.Gender doesn't support serialization. #1764

Closed
1 of 2 tasks
zjpjohn opened this issue Jul 26, 2024 · 1 comment · Fixed by #1765
Labels
bug Something isn't working

Comments

@zjpjohn
Copy link

zjpjohn commented Jul 26, 2024

Search before asking

  • I had searched in the issues and found no similar issues.

Version

0.6.0

Component(s)

Java

Minimal reproduce step

@Getter
@AllArgsConstructor
public enum Gender {
    FEMALE(1, "女") {
        @Override
        public void operate() {
            System.out.println(this.description());
        }
    },
    MALE(2, "男") {
        @Override
        public void operate() {
            System.out.println(this.description());
        }
    };

    private final Integer gender;
    private final String name;

    public Integer value() {
        return this.gender;
    }

    public String description() {
        return this.name;
    }

    public abstract void operate();
}

@Slf4j
@Data
@NoArgsConstructor
public class UserInfoDo {

    private Long userId;
    private String nickname;
    private String phone;
    private Gender gender;

    public UserInfoDo(String nickname, String phone) {
        this.nickname = nickname;
        this.phone = phone;
        this.gender = Gender.MALE;
    }

    public UserInfoDo(Long userId, String nickname, String phone) {
        this.userId = userId;
        this.nickname = nickname;
        this.phone = phone;
        this.gender = Gender.MALE;
    }

    public static void main(String[] args) {
        UserInfoDo userInfo = new UserInfoDo("张三", "13312344321");
        Fury fury = Fury.builder().withLanguage(Language.JAVA).requireClassRegistration(false).build();
        byte[] serialize = fury.serialize(userInfo);
        UserInfoDo deserialize = (UserInfoDo)fury.deserialize(serialize);
        System.out.println(deserialize.getNickname());
    }
}

What did you expect to see?

java.lang.UnsupportedOperationException: Class class com.cloud.thales.infrast.persist.Gender doesn't support serialization.

What did you see instead?

0.5.1 version is ok, but version 0.6.0 is UnsupportedOperationException

Anything Else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!
@zjpjohn zjpjohn added the bug Something isn't working label Jul 26, 2024
@chaokunyang
Copy link
Collaborator

chaokunyang commented Jul 26, 2024

Hi @zjpjohn , thanks for reporting this bug, I fixed in #1765. Seems it's introduced in #1646

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants