POSTMAN 正在返回值更改的日期字段

POSTMAN is returning date fields with changed values(POSTMAN 正在返回值更改的日期字段)
本文介绍了POSTMAN 正在返回值更改的日期字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am consuming a REST service and I am receiving a JSON with date attributes that do not match what is in my database. I have two fields called "initialDate" and "finalDate". In the database they are like this:

07/MAR/19 00:00:00
07/SEP/19 23:59:59

The database timezone:

select dbtimezone from dual;
+00:00

In my object, inside the Java class, the content of the attributes comes as:

public class Klass {

 @NotNull
 private Date initialDate; //initialDate.toString() "Thu Mar 07 00:00:00 CLT 2019"

 @NotNull
 private Date finalDate; // finalDate.toString() "Sat Sep 07 23:59:59:9 CLT 2019"

 public Date initialDate() {
    return this.initialDate == null ? null : new Date(initialDate.getTime());
 }

 public void setInitialDate() {
     this.initialDate = initialDate == null ? null : new Date(initialDate.getTime());
 }

 public Date finalDate() {
    return this.finalDate == null ? null : new Date(finalDate.getTime());
 }

 public void setFinalDate() {
    this.finalDate = finalDate == null ? null : new Date(finalDate.getTime());
 }

}

However, in my POSTMAN, it returns this:

initialDate: "2019-03-07T03:00:00Z",
finalDate: "2019-09-08T02:59:59Z"

Why is POSTMAN adding these 3 hours to my service response? I already try to change the timezone of Windows, but there's no difference.

解决方案

After some research, I've found this article that send me to a solution.

Date format Mapping to JSON Jackson

According by the write-up, In my custom class, I set the following attributes:

DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSZ");
df.setTimeZone(TimeZone.getDefault());
this.setDateFormat(df)

In this ways, I get the result as I'd like:

{
  "initialDate" : "2019-03-07T00:00:00.000-0300",
  "finalDate" : "2019-09-07T23:59:59.000-0300"
}

这篇关于POSTMAN 正在返回值更改的日期字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

SQL to Generate Periodic Snapshots from Transactions Table(用于从事务表生成定期快照的SQL)
MyBatis support for multiple databases(MyBatis支持多个数据库)
Oracle 12c SQL: Missing column Headers in result(Oracle 12c SQL:结果中缺少列标题)
SQL query to find the number of customers who shopped for 3 consecutive days in month of January 2020(查询2020年1月连续购物3天的客户数量)
How to get top 10 data weekly (This week, Previous week, Last month, 2 months ago, 3 month ago)(如何每周获取前十大数据(本周、前一周、上个月、2个月前、3个月前))
Select the latest record for an Id per day - Oracle pl sql(选择每天ID的最新记录-Oracle pl SQL)