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

de.hpi.isg.profiledb.store.json.MeasurementSerializer Maven / Gradle / Ivy

package de.hpi.isg.profiledb.store.json;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import de.hpi.isg.profiledb.store.model.Measurement;

import java.lang.reflect.Type;

/**
 * Custom serializer for {@link Measurement}s that detects the actual subclass of given instances, encodes this
 * class memebership, and then delegates serialization to that subtype.
 */
public class MeasurementSerializer implements JsonSerializer {

    @Override
    public JsonElement serialize(Measurement measurement, Type type, JsonSerializationContext jsonSerializationContext) {
        final JsonObject jsonObject = (JsonObject) jsonSerializationContext.serialize(measurement);
        jsonObject.addProperty("type", measurement.getType());
        return jsonObject;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy