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

Compilation error "@ProtoAdapter can only be applied to classes" on enum #181

Open
poschi3 opened this issue Nov 9, 2022 · 5 comments
Open

Comments

@poschi3
Copy link

poschi3 commented Nov 9, 2022

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?

@poschi3 poschi3 changed the title Error message "@ProtoAdapter can only be applied to classes" Error message "@ProtoAdapter can only be applied to classes" on enum Nov 9, 2022
@poschi3 poschi3 changed the title Error message "@ProtoAdapter can only be applied to classes" on enum Compilation error "@ProtoAdapter can only be applied to classes" on enum Nov 9, 2022
@seravat
Copy link

seravat commented Feb 22, 2023

I am facing the same issue

@fax4ever
Copy link
Contributor

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

@seravat
Copy link

seravat commented Feb 23, 2023

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

@fax4ever
Copy link
Contributor

going to check the case thank you

@fax4ever
Copy link
Contributor

you definitely right, I opened the issue https://issues.redhat.com/browse/IPROTO-261

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