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

com.alibaba.fastjson2.adapter.jackson.databind.module.SimpleSerializers Maven / Gradle / Ivy

There is a newer version: 2.0.26
Show newest version
package com.alibaba.fastjson2.adapter.jackson.databind.module;

import com.alibaba.fastjson2.adapter.jackson.databind.JsonSerializer;
import com.alibaba.fastjson2.modules.ObjectWriterModule;
import com.alibaba.fastjson2.writer.ObjectWriter;

import java.lang.reflect.Type;
import java.util.HashMap;

public class SimpleSerializers
        implements ObjectWriterModule {
    protected HashMap> classMappings;
    protected HashMap> interfaceMappings;

    protected boolean hasEnumSerializer;

    public void addSerializer(Class cls, JsonSerializer ser) {
        // Interface or class type?
        if (cls.isInterface()) {
            if (interfaceMappings == null) {
                interfaceMappings = new HashMap<>();
            }
            interfaceMappings.put(cls, ser);
        } else { // nope, class:
            if (classMappings == null) {
                classMappings = new HashMap<>();
            }
            classMappings.put(cls, ser);
            if (cls == Enum.class) {
                hasEnumSerializer = true;
            }
        }
    }

    public ObjectWriter getObjectWriter(Type objectType, Class objectClass) {
        return classMappings.get(objectType);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy