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

com.zcj.util.json.gson.GsonInstanceFox Maven / Gradle / Ivy

There is a newer version: 1.1.38
Show newest version
package com.zcj.util.json.gson;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.zcj.util.json.gson.deserializer.GsonCollectionDeserializer;
import com.zcj.util.json.gson.deserializer.GsonDateDeserializer;
import com.zcj.util.json.gson.deserializer.GsonNumberDeserializer;
import com.zcj.util.json.gson.serializer.GsonSpringFoxSerializer;
import springfox.documentation.spring.web.json.Json;

import java.util.Collection;
import java.util.Date;

public class GsonInstanceFox {

    public static final Gson GSON_FOX = new GsonBuilder()
            .registerTypeAdapter(Date.class, new GsonDateDeserializer())
            .registerTypeHierarchyAdapter(Number.class, new GsonNumberDeserializer())
            .registerTypeHierarchyAdapter(Collection.class, new GsonCollectionDeserializer())
            .registerTypeAdapter(Json.class, new GsonSpringFoxSerializer())
            .setDateFormat("yyyy-MM-dd HH:mm:ss")
            .create();

    public static final Gson GSON_FOX_SERIALIZE_NULL = new GsonBuilder()
            .serializeNulls()
            .registerTypeAdapter(Date.class, new GsonDateDeserializer())
            .registerTypeHierarchyAdapter(Number.class, new GsonNumberDeserializer())
            .registerTypeHierarchyAdapter(Collection.class, new GsonCollectionDeserializer())
            .registerTypeAdapter(Json.class, new GsonSpringFoxSerializer())
            .setDateFormat("yyyy-MM-dd HH:mm:ss")
            .create();

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy