Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: No

本文探讨了在使用Spring MVC框架时遇到的JSON输出问题,具体表现为无法将对象转换为JSON格式发送给前端。文章提供了可能的原因分析及解决方案,重点在于确保对象中存在公共的getter方法以便于自动转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type: 

@RestController或者@Controller + @ResoponseBody都已加过了还是提示该对象不能转换输出成json给前端?

请确认你的对象已经存在公共的getter方法,在自动转换过程中会用到getter方法

public class ResponseObject {
    private int code;
    private String msg;
    private Object data;

    public int getCode() {
        return code;
    }


    public String getMsg() {
        return msg;
    }


    public Object getData() {
        return data;
    }


    public ResponseObject(int code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public ResponseObject(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
org.springframework.web.bind.MethodArgumentNotValidException: Validation failed for argument [0] in public com.xymzsfxy.backend.returncode.Result com.xymzsfxy.backend.controller.admin.ProductController.update(com.xymzsfxy.backend.entity.Product) with 2 errors: [Field error in object ‘product’ on field ‘createdTime’: rejected value [2025-03-06T15:23:49.000Z]; codes [typeMismatch.product.createdTime,typeMismatch.createdTime,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [product.createdTime,createdTime]; arguments []; default message [createdTime]]; default message [Failed to convert property value of type ‘java.lang.String’ to required type ‘java.util.Date’ for property ‘createdTime’; Failed to convert from type [java.lang.String] to type [@javax.persistence.Column @com.fasterxml.jackson.annotation.JsonFormat java.util.Date] for value [2025-03-06T15:23:49.000Z]]] [Field error in object ‘product’ on field ‘updatedTime’: rejected value [2025-03-06T15:23:49.000Z]; codes [typeMismatch.product.updatedTime,typeMismatch.updatedTime,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [product.updatedTime,updatedTime]; arguments []; default message [updatedTime]]; default message [Failed to convert property value of type ‘java.lang.String’ to required type ‘java.util.Date’ for property ‘updatedTime’; Failed to convert from type [java.lang.String] to type [@javax.persistence.Column @com.fasterxml.jackson.annotation.JsonFormat java.util.Date] for value [2025-03-06T15:23:49.000Z]]] at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:177)还是这个问题
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值