The Can not parse date while it seems to the fit format ' YYYY-MM-DD ' HH:mm:ss is present in the cloud invocation in spring-T. SSS problem

Source: Internet
Author: User
Tags mongodb parse error postgresql


Recently, using spring Cloud to develop a micro-service, the following exception occurred during the test a service call B service:

Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Can not deserialize value of type java.util.Date from String "2018-04-04 14:48:30": not a valid representation (error: Failed to parse Date value '2018-04-04 14:48:30': Can not parse date "2018-04-04 14:48:30": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSS', parsing fails (leniency? null)); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Can not deserialize value of type java.util.Date from String "2018-04-04 14:48:30": not a valid representation (error: Failed to parse Date value '2018-04-04 14:48:30': Can not parse date "2018-04-04 14:48:30": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSS', parsing fails (leniency? null))

 at [Source: java.io.PushbackInputStream@4d9b0ce9; line: 1, column: 200] (through reference chain: com.zsagepay.user.dto.UserDto["createDate"]

The scene at the time:



A Tune B service query user interface, return user data (userdto), a modify return user data in the user name and avatar, ID and so on, and then drop B update user interface, update user information. There are parameters such as creation time, update time and so on in Userdto.






The cause of the exception occurred:



b The date format for creation time and update time in user data for A is: ' Yyyy-mm-dd HH:mm:ss ', a when calling B, the request data format is: ' Yyyy-mm-dd HH:mm:ss ', but b when receiving the data, Jackson was required to convert the data into Userdto objects. When Jackson transforms, the default time format is ' yyyy-mm-dd ' T ' HH:mm:ss. SSS ', so there will be an exception above.






Workaround:



Add the following annotation to the date format in Userdto to resolve:








@DateTimeFormat (pattern = "Yyyy-mm-dd HH:mm:ss")
    @JsonFormat (pattern = "Yyyy-mm-dd HH:mm:ss")


For example: Create a Time field:





@ApiModelProperty (value = "Create time; do not need to pass")
    @DateTimeFormat (pattern = "Yyyy-mm-dd HH:mm:ss")
    @JsonFormat (pattern = "Yyyy-mm-dd HH:mm:ss")
    private Date createdate;

Alibaba Cloud Hot Products

Elastic Compute Service (ECS) Dedicated Host (DDH) ApsaraDB RDS for MySQL (RDS) ApsaraDB for PolarDB(PolarDB) AnalyticDB for PostgreSQL (ADB for PG)
AnalyticDB for MySQL(ADB for MySQL) Data Transmission Service (DTS) Server Load Balancer (SLB) Global Accelerator (GA) Cloud Enterprise Network (CEN)
Object Storage Service (OSS) Content Delivery Network (CDN) Short Message Service (SMS) Container Service for Kubernetes (ACK) Data Lake Analytics (DLA)

ApsaraDB for Redis (Redis)

ApsaraDB for MongoDB (MongoDB) NAT Gateway VPN Gateway Cloud Firewall
Anti-DDoS Web Application Firewall (WAF) Log Service DataWorks MaxCompute
Elastic MapReduce (EMR) Elasticsearch

Alibaba Cloud Free Trail

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.