private String toJson(Object message) {
        if (message instanceof Iterable) {
            return Streams.stream((Iterable<?>) message)
                          .map(this::toJson)
                          .collect(Collectors.joining(",", "[", "]"));
        }

        if (message instanceof Map) {
            final Map<?, ?> map = (Map<?, ?>) message;
            return map.entrySet()
                      .stream()
                      .map(entry -> '"' + entry.getKey().toString() + "\":" + toJson(entry.getValue()))
                      .collect(Collectors.joining(",", "{", "}"));
        }

        if (!(message instanceof Message)) {
            throw new IllegalStateException(
                    "Unexpected message type : " + message.getClass() + " (expected: a subtype of " +
                    Message.class.getName() + ')');
        }

        try {
            //noinspection OverlyStrongTypeCast
            return jsonPrinter.print((Message) message);
        } catch (Exception e) {
            return Exceptions.throwUnsafely(e);
        }
    }
Creates an instance with the specified {@link Printer}.
protobuf/src/main/java/com/linecorp/armeria/server/protobuf/ProtobufResponseConverterFunction.java