@Test public void serializeTest() { PublishMessage publishMessage = PublishMessage.builder(1, "topic").build(); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(1); assertThat(publishMessage.getTopic()).isEqualTo("topic"); 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(); String json = serializeToJson(publishMessage); assertThat(json).isEqualTo("[16,1,{},\"topic\"]"); publishMessage = PublishMessage.builder(1, "topic") .arguments(Arrays.asList("abc", 23)).build(); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(1); assertThat(publishMessage.getTopic()).isEqualTo("topic"); 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("abc", 23); assertThat(publishMessage.getArgumentsKw()).isNull(); json = serializeToJson(publishMessage); assertThat(json).isEqualTo("[16,1,{},\"topic\",[\"abc\",23]]"); publishMessage = PublishMessage.builder(1, "topic") .arguments(Collections.singletonMap("colors", "blue")).build(); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(1); assertThat(publishMessage.getTopic()).isEqualTo("topic"); 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()) .containsExactly(MapEntry.entry("colors", "blue")); json = serializeToJson(publishMessage); assertThat(json).isEqualTo("[16,1,{},\"topic\",[],{\"colors\":\"blue\"}]"); publishMessage = PublishMessage.builder(2, "event").discloseMe() .arguments(Arrays.asList(23)).build(); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(2); assertThat(publishMessage.getTopic()).isEqualTo("event"); 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 = serializeToJson(publishMessage); assertThat(json).isEqualTo("[16,2,{\"disclose_me\":true},\"event\",[23]]"); publishMessage = PublishMessage.builder(2, "event").retain() .arguments(Arrays.asList(23)).build(); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(2); assertThat(publishMessage.getTopic()).isEqualTo("event"); 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 = serializeToJson(publishMessage); assertThat(json).isEqualTo("[16,2,{\"retain\":true},\"event\",[23]]"); publishMessage = PublishMessage.builder(2, "event").notExcludeMe().acknowledge() .arguments(Arrays.asList(23)).build(); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(2); assertThat(publishMessage.getTopic()).isEqualTo("event"); 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 = serializeToJson(publishMessage); assertThat(json).isEqualTo( "[16,2,{\"acknowledge\":true,\"exclude_me\":false},\"event\",[23]]"); publishMessage = PublishMessage.builder(2, "event").eligible(toSet(2L, 3L)) .exclude(toSet(7891255L, 1245751L)).arguments(Arrays.asList(23)).build(); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(2); assertThat(publishMessage.getTopic()).isEqualTo("event"); assertThat(publishMessage.getEligible()).containsOnly(2L, 3L); assertThat(publishMessage.getExclude()).containsOnly(7891255L, 1245751L); 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(); json = serializeToJson(publishMessage); assertThat(json).isEqualTo( "[16,2,{\"exclude\":[1245751,7891255],\"eligible\":[2,3]},\"event\",[23]]"); publishMessage = PublishMessage.builder(2, "event").addEligible(2).addEligible(3) .addExclude(7891255).addExclude(1245751).addArgument(23) .addArgument("color", "green").build(); assertThat(publishMessage.getCode()).isEqualTo(16); assertThat(publishMessage.getRequestId()).isEqualTo(2); assertThat(publishMessage.getTopic()).isEqualTo("event"); assertThat(publishMessage.getEligible()).containsOnly(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()) .containsExactly(MapEntry.entry("color", "green")); json = serializeToJson(publishMessage); assertThat(json).isEqualTo( "[16,2,{\"exclude\":[1245751,7891255],\"eligible\":[2,3]},\"event\",[23],{\"color\":\"green\"}]"); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.acknowledge) { generator.writeBooleanField("acknowledge", this.acknowledge); } if (!this.excludeMe) { generator.writeBooleanField("exclude_me", this.excludeMe); } if (this.discloseMe) { generator.writeBooleanField("disclose_me", this.discloseMe); } if (this.retain) { generator.writeBooleanField("retain", this.retain); } if (this.exclude != null) { generator.writeObjectField("exclude", this.exclude); } if (this.eligible != null) { generator.writeObjectField("eligible", this.eligible); } generator.writeEndObject(); generator.writeString(this.topic); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } }
PublishMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.acknowledge) { generator.writeBooleanField("acknowledge", this.acknowledge); } if (!this.excludeMe) { generator.writeBooleanField("exclude_me", this.excludeMe); } if (this.discloseMe) { generator.writeBooleanField("disclose_me", this.discloseMe); } if (this.retain) { generator.writeBooleanField("retain", this.retain); } if (this.exclude != null) { generator.writeObjectField("exclude", this.exclude); } if (this.eligible != null) { generator.writeObjectField("eligible", this.eligible); } generator.writeEndObject(); generator.writeString(this.topic); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } }
PublishMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.acknowledge) { generator.writeBooleanField("acknowledge", this.acknowledge); } if (!this.excludeMe) { generator.writeBooleanField("exclude_me", this.excludeMe); } if (this.discloseMe) { generator.writeBooleanField("disclose_me", this.discloseMe); } if (this.retain) { generator.writeBooleanField("retain", this.retain); } if (this.exclude != null) { generator.writeObjectField("exclude", this.exclude); } if (this.eligible != null) { generator.writeObjectField("eligible", this.eligible); } generator.writeEndObject(); generator.writeString(this.topic); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } 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 { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.acknowledge) { generator.writeBooleanField("acknowledge", this.acknowledge); } if (!this.excludeMe) { generator.writeBooleanField("exclude_me", this.excludeMe); } if (this.discloseMe) { generator.writeBooleanField("disclose_me", this.discloseMe); } if (this.retain) { generator.writeBooleanField("retain", this.retain); } if (this.exclude != null) { generator.writeObjectField("exclude", this.exclude); } if (this.eligible != null) { generator.writeObjectField("eligible", this.eligible); } generator.writeEndObject(); generator.writeString(this.topic); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } 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 { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.requestId); generator.writeStartObject(); if (this.acknowledge) { generator.writeBooleanField("acknowledge", this.acknowledge); } if (!this.excludeMe) { generator.writeBooleanField("exclude_me", this.excludeMe); } if (this.discloseMe) { generator.writeBooleanField("disclose_me", this.discloseMe); } if (this.retain) { generator.writeBooleanField("retain", this.retain); } if (this.exclude != null) { generator.writeObjectField("exclude", this.exclude); } if (this.eligible != null) { generator.writeObjectField("eligible", this.eligible); } generator.writeEndObject(); generator.writeString(this.topic); if (this.argumentsKw != null) { if (this.arguments == null) { generator.writeStartArray(); generator.writeEndArray(); } else { generator.writeObject(this.arguments); } generator.writeObject(this.argumentsKw); } else if (this.arguments != null) { generator.writeObject(this.arguments); } } 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; }