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

me.ruebner.jvisualizer.backend.vm.json.ReferenceValueSerializer Maven / Gradle / Ivy

Go to download

This project aims to provide an easy tool to visualize data flow and objects within the JVM. It is intended for students that are starting to learn programming with Java.

The newest version!
package me.ruebner.jvisualizer.backend.vm.json;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import me.ruebner.jvisualizer.backend.vm.values.NullValue;
import me.ruebner.jvisualizer.backend.vm.values.ReferenceValue;

import java.io.IOException;

/**
 * This is a custom serializer to convert a {@link ReferenceValue} to JSON.
 */
public class ReferenceValueSerializer extends JsonSerializer {

    @Override
    public void serialize(ReferenceValue value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        if (value instanceof NullValue nullValue) {
            jsonGenerator.writeObject(nullValue);
        } else {
            jsonGenerator.writeStartObject();
            jsonGenerator.writeNumberField("reference", value.getId());
            jsonGenerator.writeEndObject();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy