@Test public void testRoleInfoEncode() { NodeId masterNodeId = NodeId.nodeId("1"); NodeId backupNodeId1 = NodeId.nodeId("1"); NodeId backupNodeId2 = NodeId.nodeId("2"); NodeId backupNodeId3 = NodeId.nodeId("3"); List<NodeId> backupNodeIds = ImmutableList.of(backupNodeId1, backupNodeId2, backupNodeId3); RoleInfo roleInfo = new RoleInfo(masterNodeId, backupNodeIds); ObjectNode roleInfoJson = roleInfoCodec.encode(roleInfo, context); assertThat(roleInfoJson, RoleInfoJsonMatcher.matchesRoleInfo(roleInfo)); }
@Override public ObjectNode encode(RoleInfo roleInfo, CodecContext context) { checkNotNull(roleInfo, "RoleInfo cannot be null"); ObjectNode result = context.mapper().createObjectNode(); if (roleInfo.master() != null) { result.put(MASTER, roleInfo.master().id()); } ArrayNode backups = context.mapper().createArrayNode(); roleInfo.backups().forEach(backup -> backups.add(backup.id())); if (roleInfo.backups().size() != 0) { result.set(BACKUPS, backups); } return result; }
RoleInfoCodec extends JsonCodec<RoleInfo> { @Override public ObjectNode encode(RoleInfo roleInfo, CodecContext context) { checkNotNull(roleInfo, "RoleInfo cannot be null"); ObjectNode result = context.mapper().createObjectNode(); if (roleInfo.master() != null) { result.put(MASTER, roleInfo.master().id()); } ArrayNode backups = context.mapper().createArrayNode(); roleInfo.backups().forEach(backup -> backups.add(backup.id())); if (roleInfo.backups().size() != 0) { result.set(BACKUPS, backups); } return result; } }
RoleInfoCodec extends JsonCodec<RoleInfo> { @Override public ObjectNode encode(RoleInfo roleInfo, CodecContext context) { checkNotNull(roleInfo, "RoleInfo cannot be null"); ObjectNode result = context.mapper().createObjectNode(); if (roleInfo.master() != null) { result.put(MASTER, roleInfo.master().id()); } ArrayNode backups = context.mapper().createArrayNode(); roleInfo.backups().forEach(backup -> backups.add(backup.id())); if (roleInfo.backups().size() != 0) { result.set(BACKUPS, backups); } return result; }  }
RoleInfoCodec extends JsonCodec<RoleInfo> { @Override public ObjectNode encode(RoleInfo roleInfo, CodecContext context) { checkNotNull(roleInfo, "RoleInfo cannot be null"); ObjectNode result = context.mapper().createObjectNode(); if (roleInfo.master() != null) { result.put(MASTER, roleInfo.master().id()); } ArrayNode backups = context.mapper().createArrayNode(); roleInfo.backups().forEach(backup -> backups.add(backup.id())); if (roleInfo.backups().size() != 0) { result.set(BACKUPS, backups); } return result; }  @Override ObjectNode encode(RoleInfo roleInfo, CodecContext context); @Override RoleInfo decode(ObjectNode json, CodecContext context); }
RoleInfoCodec extends JsonCodec<RoleInfo> { @Override public ObjectNode encode(RoleInfo roleInfo, CodecContext context) { checkNotNull(roleInfo, "RoleInfo cannot be null"); ObjectNode result = context.mapper().createObjectNode(); if (roleInfo.master() != null) { result.put(MASTER, roleInfo.master().id()); } ArrayNode backups = context.mapper().createArrayNode(); roleInfo.backups().forEach(backup -> backups.add(backup.id())); if (roleInfo.backups().size() != 0) { result.set(BACKUPS, backups); } return result; }  @Override ObjectNode encode(RoleInfo roleInfo, CodecContext context); @Override RoleInfo decode(ObjectNode json, CodecContext context);  }