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

com.alibaba.fastjson2.adapter.jackson.databind.JsonSerializer Maven / Gradle / Ivy

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

import com.alibaba.fastjson2.JSONException;
import com.alibaba.fastjson2.JSONWriter;
import com.alibaba.fastjson2.adapter.jackson.core.JsonEncoding;
import com.alibaba.fastjson2.adapter.jackson.core.JsonGenerator;
import com.alibaba.fastjson2.adapter.jackson.databind.jsontype.TypeSerializer;
import com.alibaba.fastjson2.writer.ObjectWriter;

import java.io.IOException;
import java.lang.reflect.Type;

public abstract class JsonSerializer
        implements ObjectWriter {
    public abstract void serialize(T value, JsonGenerator gen, SerializerProvider serializers)
            throws IOException;

    @Override
    public void write(JSONWriter jsonWriter, Object object, Object fieldName, Type fieldType, long features) {
        JsonGenerator gen = new JsonGenerator(jsonWriter, null, JsonEncoding.UTF8);
        try {
            serialize((T) object, gen, null);
        } catch (IOException e) {
            throw new JSONException("write error");
        }
    }

    public Class handledType() {
        return null;
    }

    public abstract static class None
            extends JsonSerializer {
    }

    public void serializeWithType(
            T value,
            JsonGenerator gen,
            SerializerProvider serializers,
            TypeSerializer typeSer
    ) throws IOException {
        throw new JSONException("TODO");
    }
}