class 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;
    }

}