@Test public void deserializeTest() throws IOException { String json = "[16, 239714735, {}, \"com.myapp.mytopic1\"]"; PublishMessage publishMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(239714735L); assertThat(publishMessage.getTopic()).isEqualTo("com.myapp.mytopic1"); assertThat(publishMessage.getEligible()).isNull(); assertThat(publishMessage.getExclude()).isNull(); assertThat(publishMessage.isAcknowledge()).isFalse(); assertThat(publishMessage.isDiscloseMe()).isFalse(); assertThat(publishMessage.isRetain()).isFalse(); assertThat(publishMessage.isExcludeMe()).isTrue(); assertThat(publishMessage.getArguments()).isNull(); assertThat(publishMessage.getArgumentsKw()).isNull(); json = "[16, 239714735, {}, \"com.myapp.mytopic1\", [\"Hello, world!\"]]"; publishMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(239714735L); assertThat(publishMessage.getTopic()).isEqualTo("com.myapp.mytopic1"); assertThat(publishMessage.getEligible()).isNull(); assertThat(publishMessage.getExclude()).isNull(); assertThat(publishMessage.isAcknowledge()).isFalse(); assertThat(publishMessage.isDiscloseMe()).isFalse(); assertThat(publishMessage.isRetain()).isFalse(); assertThat(publishMessage.isExcludeMe()).isTrue(); assertThat(publishMessage.getArguments()).containsExactly("Hello, world!"); assertThat(publishMessage.getArgumentsKw()).isNull(); json = "[16, 239714735, {}, \"com.myapp.mytopic1\", [], {\"color\": \"orange\",\n" + "\"sizes\": [23, 42, 7]}]"; publishMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(239714735L); assertThat(publishMessage.getTopic()).isEqualTo("com.myapp.mytopic1"); assertThat(publishMessage.getEligible()).isNull(); assertThat(publishMessage.getExclude()).isNull(); assertThat(publishMessage.isAcknowledge()).isFalse(); assertThat(publishMessage.isDiscloseMe()).isFalse(); assertThat(publishMessage.isRetain()).isFalse(); assertThat(publishMessage.isExcludeMe()).isTrue(); assertThat(publishMessage.getArguments()).isEmpty(); assertThat(publishMessage.getArgumentsKw()).containsExactly( MapEntry.entry("color", "orange"), MapEntry.entry("sizes", Arrays.asList(23, 42, 7))); json = "[16, 523412, {\"disclose_me\": true}, \"com.myapp.mytopic\", [23]]"; publishMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(523412L); assertThat(publishMessage.getTopic()).isEqualTo("com.myapp.mytopic"); assertThat(publishMessage.getEligible()).isNull(); assertThat(publishMessage.getExclude()).isNull(); assertThat(publishMessage.isAcknowledge()).isFalse(); assertThat(publishMessage.isDiscloseMe()).isTrue(); assertThat(publishMessage.isRetain()).isFalse(); assertThat(publishMessage.isExcludeMe()).isTrue(); assertThat(publishMessage.getArguments()).containsExactly(23); assertThat(publishMessage.getArgumentsKw()).isNull(); json = "[16, 523412, {\"retain\": true}, \"com.myapp.mytopic\", [23]]"; publishMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(523412L); assertThat(publishMessage.getTopic()).isEqualTo("com.myapp.mytopic"); assertThat(publishMessage.getEligible()).isNull(); assertThat(publishMessage.getExclude()).isNull(); assertThat(publishMessage.isAcknowledge()).isFalse(); assertThat(publishMessage.isDiscloseMe()).isFalse(); assertThat(publishMessage.isRetain()).isTrue(); assertThat(publishMessage.isExcludeMe()).isTrue(); assertThat(publishMessage.getArguments()).containsExactly(23); assertThat(publishMessage.getArgumentsKw()).isNull(); json = "[16, 523412, {\"exclude_me\": false,\"acknowledge\":true}, \"com.myapp.mytopic\", [23]]"; publishMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(523412L); assertThat(publishMessage.getTopic()).isEqualTo("com.myapp.mytopic"); assertThat(publishMessage.getEligible()).isNull(); assertThat(publishMessage.getExclude()).isNull(); assertThat(publishMessage.isAcknowledge()).isTrue(); assertThat(publishMessage.isDiscloseMe()).isFalse(); assertThat(publishMessage.isRetain()).isFalse(); assertThat(publishMessage.isExcludeMe()).isFalse(); assertThat(publishMessage.getArguments()).containsExactly(23); assertThat(publishMessage.getArgumentsKw()).isNull(); json = "[16, 523412, {\"exclude\": [7891255,1245751],\"eligible\": [2,3]}, \"com.myapp.mytopic\", [23]]"; publishMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(523412L); assertThat(publishMessage.getTopic()).isEqualTo("com.myapp.mytopic"); assertThat(publishMessage.getEligible()).containsExactly(2, 3); assertThat(publishMessage.getExclude()).containsOnly(7891255, 1245751); assertThat(publishMessage.isAcknowledge()).isFalse(); assertThat(publishMessage.isDiscloseMe()).isFalse(); assertThat(publishMessage.isRetain()).isFalse(); assertThat(publishMessage.isExcludeMe()).isTrue(); assertThat(publishMessage.getArguments()).containsExactly(23); assertThat(publishMessage.getArgumentsKw()).isNull(); }
@SuppressWarnings("unchecked") public static PublishMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); boolean acknowledge = false; boolean excludeMe = true; boolean discloseMe = false; boolean retain = false; Set<Number> exclude = null; Set<Number> eligible = null; jp.nextToken(); Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { acknowledge = (boolean) options.getOrDefault("acknowledge", false); excludeMe = (boolean) options.getOrDefault("exclude_me", true); discloseMe = (boolean) options.getOrDefault("disclose_me", false); retain = (boolean) options.getOrDefault("retain", false); List<Number> excludeArray = (List<Number>) options.get("exclude"); if (excludeArray != null) { exclude = new HashSet<>(excludeArray); } List<Number> eligibleArray = (List<Number>) options.get("eligible"); if (eligibleArray != null) { eligible = new HashSet<>(eligibleArray); } } jp.nextToken(); String topic = jp.getValueAsString(); 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 PublishMessage(request, topic, arguments, argumentsKw, acknowledge, excludeMe, discloseMe, retain, exclude, eligible); }
PublishMessage extends WampMessage { @SuppressWarnings("unchecked") public static PublishMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); boolean acknowledge = false; boolean excludeMe = true; boolean discloseMe = false; boolean retain = false; Set<Number> exclude = null; Set<Number> eligible = null; jp.nextToken(); Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { acknowledge = (boolean) options.getOrDefault("acknowledge", false); excludeMe = (boolean) options.getOrDefault("exclude_me", true); discloseMe = (boolean) options.getOrDefault("disclose_me", false); retain = (boolean) options.getOrDefault("retain", false); List<Number> excludeArray = (List<Number>) options.get("exclude"); if (excludeArray != null) { exclude = new HashSet<>(excludeArray); } List<Number> eligibleArray = (List<Number>) options.get("eligible"); if (eligibleArray != null) { eligible = new HashSet<>(eligibleArray); } } jp.nextToken(); String topic = jp.getValueAsString(); 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 PublishMessage(request, topic, arguments, argumentsKw, acknowledge, excludeMe, discloseMe, retain, exclude, eligible); } }
PublishMessage extends WampMessage { @SuppressWarnings("unchecked") public static PublishMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); boolean acknowledge = false; boolean excludeMe = true; boolean discloseMe = false; boolean retain = false; Set<Number> exclude = null; Set<Number> eligible = null; jp.nextToken(); Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { acknowledge = (boolean) options.getOrDefault("acknowledge", false); excludeMe = (boolean) options.getOrDefault("exclude_me", true); discloseMe = (boolean) options.getOrDefault("disclose_me", false); retain = (boolean) options.getOrDefault("retain", false); List<Number> excludeArray = (List<Number>) options.get("exclude"); if (excludeArray != null) { exclude = new HashSet<>(excludeArray); } List<Number> eligibleArray = (List<Number>) options.get("eligible"); if (eligibleArray != null) { eligible = new HashSet<>(eligibleArray); } } jp.nextToken(); String topic = jp.getValueAsString(); 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 PublishMessage(request, topic, arguments, argumentsKw, acknowledge, excludeMe, discloseMe, retain, exclude, eligible); } private  PublishMessage(long requestId, String topic, @Nullable List<Object> arguments,
			@Nullable Map<String, Object> argumentsKw, boolean acknowledge,
			boolean excludeMe, boolean discloseMe, boolean retain,
			@Nullable Set<Number> exclude, @Nullable Set<Number> eligible);   PublishMessage(Builder builder); }
PublishMessage extends WampMessage { @SuppressWarnings("unchecked") public static PublishMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); boolean acknowledge = false; boolean excludeMe = true; boolean discloseMe = false; boolean retain = false; Set<Number> exclude = null; Set<Number> eligible = null; jp.nextToken(); Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { acknowledge = (boolean) options.getOrDefault("acknowledge", false); excludeMe = (boolean) options.getOrDefault("exclude_me", true); discloseMe = (boolean) options.getOrDefault("disclose_me", false); retain = (boolean) options.getOrDefault("retain", false); List<Number> excludeArray = (List<Number>) options.get("exclude"); if (excludeArray != null) { exclude = new HashSet<>(excludeArray); } List<Number> eligibleArray = (List<Number>) options.get("eligible"); if (eligibleArray != null) { eligible = new HashSet<>(eligibleArray); } } jp.nextToken(); String topic = jp.getValueAsString(); 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 PublishMessage(request, topic, arguments, argumentsKw, acknowledge, excludeMe, discloseMe, retain, exclude, eligible); } private  PublishMessage(long requestId, String topic, @Nullable List<Object> arguments,
			@Nullable Map<String, Object> argumentsKw, boolean acknowledge,
			boolean excludeMe, boolean discloseMe, boolean retain,
			@Nullable Set<Number> exclude, @Nullable Set<Number> eligible);   PublishMessage(Builder builder); static Builder builder(long requestId, String topic); @SuppressWarnings("unchecked") static PublishMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); boolean isAcknowledge(); boolean isExcludeMe(); boolean isDiscloseMe(); boolean isRetain(); String getTopic(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Nullable Set<Number> getExclude(); @Nullable Set<Number> getEligible(); @Override String toString(); }
PublishMessage extends WampMessage { @SuppressWarnings("unchecked") public static PublishMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); long request = jp.getLongValue(); boolean acknowledge = false; boolean excludeMe = true; boolean discloseMe = false; boolean retain = false; Set<Number> exclude = null; Set<Number> eligible = null; jp.nextToken(); Map<String, Object> options = ParserUtil.readObject(jp); if (options != null) { acknowledge = (boolean) options.getOrDefault("acknowledge", false); excludeMe = (boolean) options.getOrDefault("exclude_me", true); discloseMe = (boolean) options.getOrDefault("disclose_me", false); retain = (boolean) options.getOrDefault("retain", false); List<Number> excludeArray = (List<Number>) options.get("exclude"); if (excludeArray != null) { exclude = new HashSet<>(excludeArray); } List<Number> eligibleArray = (List<Number>) options.get("eligible"); if (eligibleArray != null) { eligible = new HashSet<>(eligibleArray); } } jp.nextToken(); String topic = jp.getValueAsString(); 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 PublishMessage(request, topic, arguments, argumentsKw, acknowledge, excludeMe, discloseMe, retain, exclude, eligible); } private  PublishMessage(long requestId, String topic, @Nullable List<Object> arguments,
			@Nullable Map<String, Object> argumentsKw, boolean acknowledge,
			boolean excludeMe, boolean discloseMe, boolean retain,
			@Nullable Set<Number> exclude, @Nullable Set<Number> eligible);   PublishMessage(Builder builder); static Builder builder(long requestId, String topic); @SuppressWarnings("unchecked") static PublishMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getRequestId(); boolean isAcknowledge(); boolean isExcludeMe(); boolean isDiscloseMe(); boolean isRetain(); String getTopic(); @Nullable List<Object> getArguments(); @Nullable Map<String, Object> getArgumentsKw(); @Nullable Set<Number> getExclude(); @Nullable Set<Number> getEligible(); @Override String toString(); static final int CODE; }