弹簧启动没有为返回类型找到转换器

时间:2018-04-19 14:00:42

标签: java spring-mvc spring-boot

我正在编写我的第一个Spring启动应用程序并收到以下错误。 弹簧靴应该有正确的json转换器罐,不应该抛出这种错误。 ?

  

无法写入HTTP消息:   org.springframework.http.converter.HttpMessageNotWritableException:否   转换器找到类型的返回值:class   com.test.userservice.models.dto.Response

我的回复课

class AudioField(serializers.FileField):
    def to_internal_value(self, data):
        # Check to see if it's a base64 encoded file.
        if isinstance(data, basestring):
            # Strip out the data header if it exists.
            data = re.sub(r"^data\:.+base64\,(.+)$", r"\1", data)

            try:
                decoded = base64.b64decode(data)
                mime_type = magic.from_buffer(decoded, mime=True)
                file_ext = mimetypes.guess_extension(mime_type)

            except TypeError:
                raise serializers.ValidationError(_('Not a valid file'))

            file_name = "{}{}".format(uuid.uuid4(), file_ext)

            # Check if it's a valid file extension.
            if file_ext[1:] not in settings.VOICE_VALID_FILE_EXTENSIONS:
                raise serializers.ValidationError(_('Invalid file type.'))

            # Update the data dict with new values.
            data = ContentFile(decoded, name=file_name)

            return super(AudioField, self).to_internal_value(data)

休息控制器

public class Response {

    String code;

    String message;

    public void setCode(String code) {
        this.code = code;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}

我做了小搜索并将这些依赖项添加到了pom中。仍然有错误。

 @PostMapping(value = "/register")
 public ResponseEntity<Response> registerUser(){

        Response x = new Response();
        x.setCode("test");
        x.setMessage("message");
        return new ResponseEntity<>(x, HttpStatus.OK);
 }

问题是什么? 感谢

0 个答案:

没有答案