7 changed files with 83 additions and 28 deletions
@ -0,0 +1,31 @@ |
|||||
|
package com.qs.serve.common.framework.interceptor; |
||||
|
|
||||
|
import com.alibaba.fastjson.serializer.JSONSerializer; |
||||
|
import com.alibaba.fastjson.serializer.ObjectSerializer; |
||||
|
|
||||
|
import java.io.IOException; |
||||
|
import java.lang.reflect.Type; |
||||
|
import java.text.SimpleDateFormat; |
||||
|
import java.time.LocalDateTime; |
||||
|
import java.time.format.DateTimeFormatter; |
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* @author YenHex |
||||
|
* @since 2024/7/18 |
||||
|
*/ |
||||
|
public class LocalDateTimeFormatSerializer implements ObjectSerializer { |
||||
|
|
||||
|
@Override |
||||
|
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException { |
||||
|
if (object == null) { |
||||
|
serializer.out.writeNull(); |
||||
|
return; |
||||
|
} |
||||
|
LocalDateTime date = (LocalDateTime) object; |
||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
||||
|
String timeString = formatter.format(date); |
||||
|
serializer.write(timeString); |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue