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

com.atlan.serde.RemovableSerializer Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
/* SPDX-License-Identifier: Apache-2.0
   Copyright 2022 Atlan Pte. Ltd. */
package com.atlan.serde;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import java.io.IOException;

/**
 * Serialization of the {@link Removable} placeholder object, to allow the SDK to serialize null values only when
 * it should intentionally clear out some value.
 */
public class RemovableSerializer extends StdSerializer {
    private static final long serialVersionUID = 2L;

    public RemovableSerializer() {
        this(null);
    }

    public RemovableSerializer(Class t) {
        super(t);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void serialize(Removable removable, JsonGenerator gen, SerializerProvider sp)
            throws IOException, JsonProcessingException {
        if (removable.isJsonNull()) {
            if (removable.getType() == Removable.TYPE.PRIMITIVE) {
                gen.writeNull();
            } else {
                gen.writeStartArray();
                gen.writeEndArray();
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy