Annotation Type JsonFormat

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Annotation Type JsonFormat相关的知识,希望对你有一定的参考价值。

最近在调试接口时发现:接口传递过来的jSON数据格式中时间格式是字符串的形式:

{"name":"满300送50",
	"merchantId":"1",
	"needMoney":"100",
	"money":"50",
	"useMoney":"300",
	"beginDatetime":"2017-09-27 10:00:00",
	"endDatetime":"2017-09-27 10:00:00"
}

而java绑定的实体文件是Date格式的:

private Date beginDatetime;
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    public Date getBeginDatetime() {
        return beginDatetime;
    }

    public void setBeginDatetime(Date beginDatetime) {
        this.beginDatetime = beginDatetime;
    }

调用接口的时候就会报HTTP Status 400 – Bad Request的错误,表示

The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).

在getter方法上添加@JsonFormat注解

@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    public Date getBeginDatetime() {
        return beginDatetime;
    }


本文出自 “一个程序媛的自我修养” 博客,请务必保留此出处http://qianqiansun.blog.51cto.com/13271301/1968950

以上是关于Annotation Type JsonFormat的主要内容,如果未能解决你的问题,请参考以下文章

Annotation type expected 预期注释类型

Rust sometimes needs manual type annotation

Rust sometimes needs manual type annotation

Rust sometimes needs manual type annotation

Test is not an annotation type 异常

The attribute required is undefined for the annotation type XmlElementRef