You need to develop a chat application, which allows the display of emoticons and images together with text messages.
How should you configure a WebSocket endpoints to receive both text and binary messages?
A. Create two @onMessage methods in the same endpoint with appropriate parameter types.
B. Define the @onMessage methods in your endpoint with Object as parameter and check the actual type in your code.
C. You can achieve this only by creating separate WebSocket endpoints for each message type.
D. Create two @onMessage methods, each with appropriate decoder attribute in the same endpoint.
Answer is A because we don’t need to transform messages into some Objects
Correct Answer:D
Annotated endpoints: it’s all about passing the right type of parameters in the method annotated with @ONMESSAGES
Receiving text, binary messages as Java objects
Text and binary messages sent by a WebSocket peer can be received as Java objects within your message handling logic (annotated or programmatic).
But how would the on-wire format (text/binary) to Java object transformation take place ?
This is where Decoders come into the picture. An implementation of a javax.websocket.Decoder provides the necessary logic to convert a message from it’s on-wire format into it’s Java representation.
https://abhishek-gupta.gitbook.io/java…/receiving-messages