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

Serializing 'naked' enum throws exception java.lang.IllegalAccessException #48

Closed
readlearncode opened this Issue Sep 16, 2017 · 0 comments

Comments

Projects
None yet
3 participants
@readlearncode

readlearncode commented Sep 16, 2017

Serialising an enum throws the following edited exception:

javax.json.bind.JsonbException: Error getting value on: 
sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedParameterizedTypeImpl@1f57539
...
Caused by: java.lang.IllegalAccessException: 
Class org.eclipse.yasson.internal.model.GetFromGetter can not access a member of class 
sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedTypeBaseImpl 
with modifiers "public final"
	at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)
	at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:296)
	at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:288)
	at java.lang.reflect.Method.invoke(Method.java:491)
	at org.eclipse.yasson.internal.model.GetFromGetter.internalGetValue(GetFromGetter.java:28)
	at org.eclipse.yasson.internal.model.GetValueCommand.getValue(GetValueCommand.java:34)

The enum:

public enum Binding {
    HARD_BACK {
        public String toString() {
            return "Hard Back";
        }
    }, SOFT_BACK {
        public String toString() {
            return "Soft Back";
        }
    }
}

The serialisation code: JsonbBuilder.create().toJson(Binding.HARD_BACK);

Dependecies:
org.eclipse/yasson: 1.0
javax.json.bind-api: 1.0
org.glassfish/javax.json: 1.1
javax.json/javax.json-api: 1.1

CODE: https://github.com/readlearncode/Java-EE-8-Sampler/blob/master/json-b-1-0/src/main/java/com/readlearncode/devWorks/overview/EnumExample.java
TEST: https://github.com/readlearncode/Java-EE-8-Sampler/blob/master/json-b-1-0/src/test/java/com/readlearncode/devWorks/overview/EnumExampleTest.java

@m0mus m0mus added the bug label Sep 17, 2017

@m0mus m0mus added this to the 1.0.1 milestone Sep 17, 2017

bravehorsie added a commit that referenced this issue Sep 18, 2017

Fixes #48, fixes #47
Serializers and deserializers for anonymous enum value classes are now properly resolved.
Serializer is now using value.name()
Deserializer is using Enum#valueOf()

Signed-off-by: Roman Grigoriadi <roman.grigoriadi@oracle.com>

@m0mus m0mus closed this in #50 Sep 25, 2017

m0mus added a commit that referenced this issue Sep 25, 2017

Fixes #48, fixes #47 (#50)
Serializers and deserializers for anonymous enum value classes are now properly resolved.
Serializer is now using value.name()
Deserializer is using Enum#valueOf()

Signed-off-by: Roman Grigoriadi <roman.grigoriadi@oracle.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment