code: protected final void sendObjectToSocket(Object objectToSend, WriteCallback cb) {
          Session sess = this.getSession();
          if (sess != null) {
              String json;
              try {
                  json = this.mapper.writeValueAsString(objectToSend);
              } catch (JsonProcessingException e) {
                  throw new RuntimeException("Failed to serialize object", e);
              }
              sess.getRemote().sendString(json, cb);
          }
      }
docs: send object to client and serialize it using JSON
  
  @param objectToSend  the object to send
  @param cb the callback after sending the message