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 serialization error with Java 17 #155

Closed
bergerdenes opened this issue Oct 25, 2021 · 4 comments
Closed

Enum serialization error with Java 17 #155

bergerdenes opened this issue Oct 25, 2021 · 4 comments

Comments

@bergerdenes
Copy link

I have created a test scenario, with an enum and a class with a field typed to this enum.

public enum SimpleEnum {
    ONE, TWO
}

(...)

public class SimpleClass {
    private final String name;
    private final SimpleEnum myEnum;

    public SimpleClass(String name, SimpleEnum myEnum) {
        this.name = name;
        this.myEnum = myEnum;
    }

    public String getName() {
        return name;
    }

    public SimpleEnum getMyEnum() {
        return myEnum;
    }
}

When I try to serialize this class with Java 17, the enum value is serialized to null

SimpleClass mc = new SimpleClass("MyName", SimpleEnum.ONE);
System.out.println(JsonWriter.objectToJson(mc));

output:
{"@type":"myPackage.SimpleClass","name":"MyName","myEnum":{"name":null}}

@bergerdenes bergerdenes changed the title Enum serialization Enum serialization error with Java 17 Oct 25, 2021
@wwang-talend
Copy link
Contributor

#156
maybe this help? i try to set this : "--illegal-access=deny" on jvm parameters, it works, the same between jdk11 and jdk17

@bergerdenes
Copy link
Author

bergerdenes commented Feb 10, 2022

#156 maybe this help? i try to set this : "--illegal-access=deny" on jvm parameters, it works, the same between jdk11 and jdk17

OpenJDK 64-Bit Server VM warning: Ignoring option --illegal-access=deny; support was removed in 17.0
And it does not work either.

@jdereg
Copy link
Owner

jdereg commented Oct 14, 2022

Recent fixes to include serialization of Enums were added and included in json-io 4.14.0. Please let me know if that corrects this issue for you.

@bergerdenes
Copy link
Author

It works now but too late, moved away from this lib to Jackson last July

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

3 participants