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