From ce8fe48393f8efe101db162fb5afcf46fd2f7d7d Mon Sep 17 00:00:00 2001 From: Chen Qian Date: Mon, 11 Jan 2021 11:10:03 +0800 Subject: [PATCH] append warn log only when MediaType present (#28) --- ...stractResponseBodyReturnValueResolver.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/restlight-core/src/main/java/esa/restlight/core/resolver/result/AbstractResponseBodyReturnValueResolver.java b/restlight-core/src/main/java/esa/restlight/core/resolver/result/AbstractResponseBodyReturnValueResolver.java index c978bca3..f2e39be4 100644 --- a/restlight-core/src/main/java/esa/restlight/core/resolver/result/AbstractResponseBodyReturnValueResolver.java +++ b/restlight-core/src/main/java/esa/restlight/core/resolver/result/AbstractResponseBodyReturnValueResolver.java @@ -97,20 +97,24 @@ protected byte[] resolve0(Object returnValue, } HttpResponseSerializer serializer = null; - for (MediaType mediaType : mediaTypes) { - for (HttpResponseSerializer ser : serializers) { - if (ser.supportsWrite(mediaType, returnValue.getClass())) { - serializer = ser; - break; + if (mediaTypes.isEmpty()) { + serializer = serializers.get(0); + } else { + for (MediaType mediaType : mediaTypes) { + for (HttpResponseSerializer ser : serializers) { + if (ser.supportsWrite(mediaType, returnValue.getClass())) { + serializer = ser; + break; + } } } + if (serializer == null) { + logger.warn("Failed to find serializer for media type '{}', try to use default serializer.", + mediaTypes); + serializer = serializers.get(0); + } } - if (serializer == null) { - logger.warn("Failed to find serializer for media type '{}', try to use default serializer.", - mediaTypes); - serializer = serializers.get(0); - } final Object returnValueToWrite = serializer.customResponse(request, response, returnValue); return Serializers.serializeBySerializer(serializer, returnValueToWrite, response); }