Basically, can I use:
@OnMessage
public void handleMessage(Message message, Session session) {
instead of:
@OnMessage
public void handleMessage(String message, Session session) {
The message class would look something like:
public class Message {
private String action;
private String value;
}
Following the documentation, it is not possible:
The allowed parameters are:
Exactly one of any of the following choices
if the method is handling text messages:
String to receive the whole message
Java primitive or class equivalent to receive the whole message converted to that type
String and boolean pair to receive the message in parts
Reader to receive the whole message as a blocking stream
any object parameter for which the endpoint has a text decoder (Decoder.Text or Decoder.TextStream).
if the method is handling binary messages:
byte[] or ByteBuffer to receive the whole message
byte[] and boolean pair, or ByteBuffer and boolean pair to receive the message in parts
InputStream to receive the whole message as a blocking stream
any object parameter for which the endpoint has a binary decoder (Decoder.Binary or Decoder.BinaryStream).
if the method is handling pong messages:
PongMessage for handling pong messages
and Zero to n String or Java primitive parameters annotated with the PathParam annotation for server endpoints.
and an optional Session parameter
https://docs.oracle.com/javaee/7/api/javax/websocket/OnMessage.html
But if you use JAXRS (with RESTEasy, Jersey or CXF), you will be able to parse directly in the target Object using Json Provider (Jackson, Gson).