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

io.yawp.commons.utils.json.IdRefJsonSerializerDeserializer Maven / Gradle / Ivy

There is a newer version: 2.08alpha
Show newest version
package io.yawp.commons.utils.json;

import com.google.gson.*;
import io.yawp.repository.IdRef;
import io.yawp.repository.Repository;

import java.lang.reflect.Type;

public class IdRefJsonSerializerDeserializer implements JsonSerializer>, JsonDeserializer> {

    private Repository r;

    public IdRefJsonSerializerDeserializer(Repository r) {
        this.r = r;
    }

    @Override
    public JsonElement serialize(IdRef idRef, Type type, JsonSerializationContext ctx) {
        return new JsonPrimitive(idRef.toString());
    }

    @Override
    public IdRef deserialize(JsonElement json, Type type, JsonDeserializationContext ctx) throws JsonParseException {
        String path = json.getAsJsonPrimitive().getAsString();
        return IdRef.parse(r, null, path);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy