@Test public void deserializeTest() throws IOException { String json = "[36, 5512315355, 4429313566, {}]"; EventMessage eventMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(5512315355L); assertThat(eventMessage.getPublicationId()).isEqualTo(4429313566L); assertThat(eventMessage.getTopic()).isNull(); assertThat(eventMessage.getPublisher()).isNull(); assertThat(eventMessage.isRetained()).isFalse(); assertThat(eventMessage.getArguments()).isNull(); assertThat(eventMessage.getArgumentsKw()).isNull(); json = "[36, 5512315355, 4429313566, {}, [\"Hello, world!\"]]"; eventMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(5512315355L); assertThat(eventMessage.getPublicationId()).isEqualTo(4429313566L); assertThat(eventMessage.getTopic()).isNull(); assertThat(eventMessage.getPublisher()).isNull(); assertThat(eventMessage.isRetained()).isFalse(); assertThat(eventMessage.getArguments()).containsExactly("Hello, world!"); assertThat(eventMessage.getArgumentsKw()).isNull(); json = "[36, 5512315355, 4429313566, {}, [], {\"color\": \"orange\",\"sizes\": [23, 42, 7]}]"; eventMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(5512315355L); assertThat(eventMessage.getPublicationId()).isEqualTo(4429313566L); assertThat(eventMessage.getTopic()).isNull(); assertThat(eventMessage.getPublisher()).isNull(); assertThat(eventMessage.isRetained()).isFalse(); assertThat(eventMessage.getArguments()).isEmpty(); assertThat(eventMessage.getArgumentsKw()).containsExactly( MapEntry.entry("color", "orange"), MapEntry.entry("sizes", Arrays.asList(23, 42, 7))); json = "[36, 5512315355, 4429313566, {}, [\"a\",\"b\"], {\"color\": \"orange\",\"sizes\": [23, 42, 7]}]"; eventMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(5512315355L); assertThat(eventMessage.getPublicationId()).isEqualTo(4429313566L); assertThat(eventMessage.getTopic()).isNull(); assertThat(eventMessage.getPublisher()).isNull(); assertThat(eventMessage.isRetained()).isFalse(); assertThat(eventMessage.getArguments()).containsExactly("a", "b"); assertThat(eventMessage.getArgumentsKw()).containsExactly( MapEntry.entry("color", "orange"), MapEntry.entry("sizes", Arrays.asList(23, 42, 7))); json = "[36, 5512315355, 4429313566, {\"topic\":\"the_topic\"}, [\"Hello, world!\"]]"; eventMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(5512315355L); assertThat(eventMessage.getPublicationId()).isEqualTo(4429313566L); assertThat(eventMessage.getTopic()).isEqualTo("the_topic"); assertThat(eventMessage.getPublisher()).isNull(); assertThat(eventMessage.isRetained()).isFalse(); assertThat(eventMessage.getArguments()).containsExactly("Hello, world!"); assertThat(eventMessage.getArgumentsKw()).isNull(); json = "[36, 5512315355, 4429313566, {\"topic\":\"the_topic\", \"publisher\":1234}, [\"Hello, world!\"]]"; eventMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(5512315355L); assertThat(eventMessage.getPublicationId()).isEqualTo(4429313566L); assertThat(eventMessage.getTopic()).isEqualTo("the_topic"); assertThat(eventMessage.getPublisher()).isEqualTo(1234); assertThat(eventMessage.isRetained()).isFalse(); assertThat(eventMessage.getArguments()).containsExactly("Hello, world!"); assertThat(eventMessage.getArgumentsKw()).isNull(); json = "[36, 5512315355, 4429313566, {\"retained\":false}, [\"Not Retained\"]]"; eventMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(5512315355L); assertThat(eventMessage.getPublicationId()).isEqualTo(4429313566L); assertThat(eventMessage.getTopic()).isNull(); assertThat(eventMessage.getPublisher()).isNull(); assertThat(eventMessage.isRetained()).isFalse(); assertThat(eventMessage.getArguments()).containsExactly("Not Retained"); assertThat(eventMessage.getArgumentsKw()).isNull(); json = "[36, 5512315355, 4429313566, {\"retained\":true}, [\"Retained\"]]"; eventMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(eventMessage.getCode()).isEqualTo(36); assertThat(eventMessage.getSubscriptionId()).isEqualTo(5512315355L); assertThat(eventMessage.getPublicationId()).isEqualTo(4429313566L); assertThat(eventMessage.getTopic()).isNull(); assertThat(eventMessage.getPublisher()).isNull(); assertThat(eventMessage.isRetained()).isTrue(); assertThat(eventMessage.getArguments()).containsExactly("Retained"); assertThat(eventMessage.getArgumentsKw()).isNull(); }
public static EventMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long subscription = jp.getLongValue(); jp.nextToken(); long publication = jp.getLongValue(); jp.nextToken(); String topic = null; Number publisher = null; boolean retained = false; Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { topic = (String) details.get("topic"); publisher = (Number) details.get("publisher"); retained = (boolean) details.getOrDefault("retained", false); } List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new EventMessage(subscription, publication, topic, publisher, retained, arguments, argumentsKw); }
EventMessage extends WampMessage { public static EventMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long subscription = jp.getLongValue(); jp.nextToken(); long publication = jp.getLongValue(); jp.nextToken(); String topic = null; Number publisher = null; boolean retained = false; Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { topic = (String) details.get("topic"); publisher = (Number) details.get("publisher"); retained = (boolean) details.getOrDefault("retained", false); } List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new EventMessage(subscription, publication, topic, publisher, retained, arguments, argumentsKw); } }
EventMessage extends WampMessage { public static EventMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long subscription = jp.getLongValue(); jp.nextToken(); long publication = jp.getLongValue(); jp.nextToken(); String topic = null; Number publisher = null; boolean retained = false; Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { topic = (String) details.get("topic"); publisher = (Number) details.get("publisher"); retained = (boolean) details.getOrDefault("retained", false); } List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new EventMessage(subscription, publication, topic, publisher, retained, arguments, argumentsKw); } EventMessage(long subscriptionId, long publicationId, @Nullable String topic,
			@Nullable Number publisher, boolean retained,
			@Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw);  EventMessage(@Nullable String receiverWebSocketSessionId, long subscription,
			long publication, @Nullable String topic, @Nullable Number publisher,
			boolean retained, PublishMessage publishMessage); }
EventMessage extends WampMessage { public static EventMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long subscription = jp.getLongValue(); jp.nextToken(); long publication = jp.getLongValue(); jp.nextToken(); String topic = null; Number publisher = null; boolean retained = false; Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { topic = (String) details.get("topic"); publisher = (Number) details.get("publisher"); retained = (boolean) details.getOrDefault("retained", false); } List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new EventMessage(subscription, publication, topic, publisher, retained, arguments, argumentsKw); } EventMessage(long subscriptionId, long publicationId, @Nullable String topic,
			@Nullable Number publisher, boolean retained,
			@Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw);  EventMessage(@Nullable String receiverWebSocketSessionId, long subscription,
			long publication, @Nullable String topic, @Nullable Number publisher,
			boolean retained, PublishMessage publishMessage); static EventMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getSubscriptionId(); long getPublicationId(); @Nullable String getTopic(); @Nullable Number getPublisher(); boolean isRetained(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Override String toString(); }
EventMessage extends WampMessage { public static EventMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long subscription = jp.getLongValue(); jp.nextToken(); long publication = jp.getLongValue(); jp.nextToken(); String topic = null; Number publisher = null; boolean retained = false; Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { topic = (String) details.get("topic"); publisher = (Number) details.get("publisher"); retained = (boolean) details.getOrDefault("retained", false); } List<Object> arguments = null; JsonToken token = jp.nextToken(); if (token == JsonToken.START_ARRAY) { arguments = ParserUtil.readArray(jp); } Map<String, Object> argumentsKw = null; token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { argumentsKw = ParserUtil.readObject(jp); } return new EventMessage(subscription, publication, topic, publisher, retained, arguments, argumentsKw); } EventMessage(long subscriptionId, long publicationId, @Nullable String topic,
			@Nullable Number publisher, boolean retained,
			@Nullable List<Object> arguments, @Nullable Map<String, Object> argumentsKw);  EventMessage(@Nullable String receiverWebSocketSessionId, long subscription,
			long publication, @Nullable String topic, @Nullable Number publisher,
			boolean retained, PublishMessage publishMessage); static EventMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getSubscriptionId(); long getPublicationId(); @Nullable String getTopic(); @Nullable Number getPublisher(); boolean isRetained(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Override String toString(); static final int CODE; }