All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitee.easyopen.serializer.LocalDateTimeSerializer Maven / Gradle / Ivy

Go to download

easyopen mini版,保留基本签名校验,文档功能。https://gitee.com/durcframework/easyopen

There is a newer version: 1.0.4
Show newest version
package com.gitee.easyopen.serializer;

import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import java.lang.reflect.Type;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * gson处理LocalDateTime
 */
public class LocalDateTimeSerializer implements JsonSerializer {

    private String pattern;

    /**
     * @param pattern 日期格式
     */
    public LocalDateTimeSerializer(String pattern) {
        this.pattern = pattern;
    }

    @Override
    public JsonElement serialize(LocalDateTime localDateTime, Type type, JsonSerializationContext jsonSerializationContext) {
        return new JsonPrimitive(localDateTime.format(DateTimeFormatter.ofPattern(pattern)));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy