-
Notifications
You must be signed in to change notification settings - Fork 43
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
Clarify search order of Encoders / Decoders #289
Comments
Then there is the issue with merging decoders in common between the annotations and configuration. It could be argued that just like The javadoc is unclear on this behavior. |
Clarification is (potentially) a change in behaviour so this will need to wait for Jakarta EE 10. As a note to self I don't think the API will need to change (but haven't thought about this much) but don't forget to update the spec document and the Javadoc. |
I agree. This seems like a need for updated documentation and/or javadoc, along with some new TCK tests. |
To me, it makes sense for the "/purchase" endpoint to use "AppleDecoder.class, PearDecoder.class, FruitDecoder.class" while the "/floo" endpoint to use "CherryDecoder.class, BananaDecoder.class". Shouldn't each URI path be mapped to a particular config? However, I'm not familiar with this scenario: "could be argued that just like @serverendpoint(value="/echo") is overridden if using ServerEndpointConfig.getPath()". @joakime Could you provide an example? Overriding encoders / decoders could make sense. |
@volosied In the original example ... ServerEndpointConfig.Builder.create(PurchaseEndpoint.class, "/floo") The Since the annotation doesn't support multiple paths, or having multiple annotations, the end user has to create the config manually to add. I wish we had either defined the annotation in a way that multiple configurations could be defined (use annotations only), or that it only applied to 1 configuration (never mix with manual endpoint config). Frankly, the "platform" decoders / encoders should have also been mandatory to declare in your decoders/encoders to use them (as their behaviors have never been fully defined) |
I see. Thanks for the explanation and the background information. I'm not sure what the official proposal is, but It makes sense to use the Annotated Endpoints values for the encoders and decoders by default as you suggested before. If any encoders / decoders are set via the ServerEndpointConfig.Builder then they should override the ones set via annotation. Since you mentioned the subprotocols, extensions, and configurator. Should this overriding process be extended to them, too? |
How about this then:
Same rules for sub-protocols, extensions and configurators (except there is only a single configurator) Is deprecating everything encode and decoder related a step too far? |
I'd expect the programmatic API to override annotations (so that the annotated class can be reused if the customer wants to). That I can see in the most Specs. The Javadoc to
So the decoders(encoders,...) are set, not added. If addition would be a requirement, that would need to be done some other way:
In JAX-RS Spec (Section 4.2.4), the user-defined providers always have priority over the platform providers. I imagine the same behaviour for Encoders/Decoders here. just my $0.02 |
I'm good with this. Are we going to have the primitive decoders in the WebSocket spec too?
Yeah, that ship has sailed. |
We need to be careful about the order of the resulting set of encoders / decoders when we have these new rules. |
Do you mean to allow users to override the platform primitive types decoders? |
This is part of the discussion at #213 . Basically, this statement means that the primitive encoders / decoders are defined and implemented in the WebSocket spec for every websocket implementation to use. There's so many behavior differences in things like ...
As for having a requirement to declare their use in the encoders / decoders for each endpoint, that is still undecided. I personally think it was a mistake to have support for anything but String / ByteBuffer, but that ship has long since sailed. |
Is the typical user expectation with the current API that EndpointConfig Encoders/Decoders are in addition to those configured via Annotation or that they replace them? The current Javadoc suggests replacement so on reflection I'd prefer to do that if possible. If we need to handle addition and replacement then so be it. The current spec is pretty clear about how String <-> primitive (or class equivalent) is meant to behave. There shouldn't be that much difference. No objection to adding a utility class to do the conversion. Looking at the current spec text I think the platform encoders always have to be used unless overridden by EndpointConfig or Annotation. |
I cannot find a TCK test for this. Can you? Speaking for Jetty ... This produces an interesting side effect though. @ServerEndpoint(value = "/time", encoders = TimeEncoder.class)
public class TimeSocket {
// ...
} and later use a ServerEndpointConfig timeconfig = ServerEndpointConfig.Builder
.create(TimeSocket.class, "/alt-time")
.encoders(List.of()) // want to have no encoders, want to rely on primitives, but we are instead relying on TimeEncoder.class from the annotation
.build(); you can only replace them with a no-op implementation. ServerEndpointConfig timeconfig = ServerEndpointConfig.Builder
.create(TimeSocket.class, "/alt-time")
.encoders(List.of(NoOpTimeEncoder.class))
.build(); |
I do not think the API should come with the primitive-type coders. The Spec would need to force the implementation to use them (otherwise they are there for no reason), and the implementation will try to find its way to override them if it wants to support additional conversions from String representation (as mentioned |
As outlined in #39 (comment) ...
Danny Coward states ...
What is the search order when the "developer provided ones" comes from 2 places (annotations and configuration)?
and in the container init ...
What is the resulting search order of decoders?
Option 1: (EndpointConfig wins over Annotations)
Option 2: (Annotation wins over EndpointConfig)
(Does the order of the Platform Decoders matter? I don't think so)
The text was updated successfully, but these errors were encountered: