Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use @ jsonFormat to solve the problem of time conversion failure

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to use @ jsonFormat to solve the problem of time conversion failure". In daily operation, I believe many people have doubts about how to use @ jsonFormat to solve the problem of time conversion failure. I have consulted all kinds of materials and sorted out simple and useful operation methods. I hope it will be helpful for you to answer the question of "how to use @ jsonFormat to solve the problem of time conversion failure"! Next, please follow the editor to study!

Black question mark face

1. Check the project configuration information

Oh, discovering that the project uses fastJson as JSON MessageConverter is the biggest difference from the previous project configuration. FastJosn does not support the @ JsonFormat method of jackson. All right, comment out, springboot2.x after the default use of jackson as JSON MessageConverter without the introduction of jar package, no configuration, can be used directly, problem solved.

The time conversion method is as follows:

Add @ JsonFormat (pattern= "yyyy-MM-dd HH:mm:ss", timezone= "GMT+8") to the entity class field

@ JsonFormat use

2. FastJson does not support @ JonFormat. What if I still want to use fastJson?

Online to see the opinions of the bosses in the entity class to add @ JsonFiled (format = "yyyy-MM-dd") happy to try, all kinds of postures are not successful or invalid millisecond value.

Emm, do not give up, read in an article that fastjson no longer supports directly adding @ JsonFiled to fields, but must be written on getter and setter methods. Due to the use of the @ Data annotation of lombok, this practice has not been tried.

However, I saw that the bosses said that the new version of fastjson had been fixed, so I downloaded the 1.2.54 version of fastjson and added time formatting to the configuration to solve the problem perfectly.

FastJosn version

No need to add @ JsonFiled

If you have any questions, you can discuss and leave a message to study.

At this point, the study on "how to use @ jsonFormat to solve the problem of time conversion failure" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report