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

Classes can't implement multiple Decoder/Encoder interfaces #50

Open
micheljung opened this issue Feb 7, 2021 · 0 comments · May be fixed by #74
Open

Classes can't implement multiple Decoder/Encoder interfaces #50

micheljung opened this issue Feb 7, 2021 · 0 comments · May be fixed by #74

Comments

@micheljung
Copy link

micheljung commented Feb 7, 2021

When implementing a class like this:

public class UuidDecoder implements Decoder.TextStream<UUID>, Decoder, Decoder.Binary<UUID>, Decoder.Text<UUID> {
    public UuidDecoder() {
        System.out.println("OK!");
    }

    @Override
    public void init(EndpointConfig config) {

    }

    @Override
    public void destroy() {

    }

    @Override
    public UUID decode(Reader reader) throws DecodeException, IOException {
        return UUID.fromString(CharStreams.toString(reader));
    }

    @Override
    public UUID decode(ByteBuffer bytes) throws DecodeException {
        return UUID.fromString(new String(bytes.array()));
    }

    @Override
    public boolean willDecode(ByteBuffer bytes) {
        try {
            UUID.fromString(new String(bytes.array()));
            return true;
        } catch (IllegalArgumentException e) {
            return false;
        }
    }

    @Override
    public UUID decode(String s) throws DecodeException {
        return UUID.fromString(s);
    }

    @Override
    public boolean willDecode(String s) {
        try {
            UUID.fromString(s);
            return true;
        } catch (IllegalArgumentException e) {
            return false;
        }
    }
}

And using it like this:

@ServerEndpoint(value = "/api/ws/search/{id}", decoders = UuidDecoder.class)
public class SearchResource {
}

Only the binary encoder/decoder is registered, since EncodingFactory checks for interface implementations using else-if.

See https://stackoverflow.com/questions/60134388/how-to-use-custom-encoder-and-decoder-in-quarkus

I'll submit a PR to fix this.

micheljung added a commit to micheljung/quarkus-http that referenced this issue Feb 7, 2021
micheljung added a commit to micheljung/quarkus-http that referenced this issue Feb 7, 2021
@micheljung micheljung linked a pull request Apr 28, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant