infinispan / infinispan/protostream
Compilation error "@ProtoAdapter can only be applied to classes" on enum
- Dominant language
- Java
- Stars
- 56
- Forks
- 39
- Avg merge
- 5h 36m
- Merged PRs (30d)
- 5
Description
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](https://infinispan.org/docs/stable/titles/encoding/encoding.html#protoadapter) 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](https://github.com/infinispan/protostream/blob/main/integrationtests/src/test/resources/org/infinispan/protostream/integrationtests/processor/MarshallExternals.java#L33) doing this. My example files are adopted from there:
ColorEnum.java
```java
package com.example;
public enum ColorEnum {
RED, GREEN, BLUE
}
```
ColorEnumAdapter.java
```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?
Contributor guide
Research direction
Start with the compiler error in ColorEnumAdapter.java and compare its annotation usage with integrationtests/src/test/resources/org/infinispan/protostream/integrationtests/processor/MarshallExternals.java. Check the linked ProtoAdapter documentation and test example to determine whether enum adapters should compile or the documentation and example need correction. Done means the documented behavior, processor behavior, and example agree.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100