me.ruebner.jvisualizer.backend.vm.json.ReferenceValueSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jvisualizer Show documentation
Show all versions of jvisualizer Show documentation
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();
}
}
}