Compilation error "@ProtoAdapter can only be applied to classes" on enum
Hi, I wrote a ProtoAdapter for an Enum and get a compilation error:
[ERROR] /home/user/.../caching/src/main/java/com/example/ColorEnumAdapter.java:[7,8] @ProtoAdapter can only be applied to classes.
But documentation says
@ProtoAdapter is a marshalling adapter for a class or enum that you cannot annotate directly.
I also found an Unit Test in source code doing this. My example files are adopted from there:
ColorEnum.java
package com.example;
public enum ColorEnum {
RED, GREEN, BLUE
}
ColorEnumAdapter.java
package com.example;
import org.infinispan.protostream.annotations.ProtoAdapter;
import org.infinispan.protostream.annotations.ProtoEnumValue;
@ProtoAdapter(ColorEnum.class)
public enum ColorEnumAdapter {
@ProtoEnumValue(number = 0, name = "red")
RED,
@ProtoEnumValue(number = 1, name = "green")
GREEN,
@ProtoEnumValue(number = 2, name = "blue")
BLUE
}
Can you help me to find out what I'm doing wrong?
I am facing the same issue
Hi @poschi3 and @seravat.
Are you using the ColorEnumAdapter to generate the schema with an @AutoProtoSchemaBuilder?
E.g.:
@AutoProtoSchemaBuilder(includeClasses = { Developer.class, ColorAdapter.class },
schemaFileName = "developer.proto", schemaFilePath = "proto")
public interface DeveloperSchema extends GeneratedSchema {
DeveloperSchema INSTANCE = new DeveloperSchemaImpl();
}
Could you share the code that uses the adapter please? Thank you Fabio
So, I found that in the class annotated with @AutoProtoSchemaBuilder you cannot use @AutoProtoSchemaBuilder(basePackage=xxx) with enums you have to use @AutoProtoSchemaBuilder(includeClasses = { xxx.class, yyy.class }) for it to work
going to check the case thank you
you definitely right, I opened the issue https://issues.redhat.com/browse/IPROTO-261