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

org.jobrunr.utils.mapper.gson.JobParameterDeserializer Maven / Gradle / Ivy

package org.jobrunr.utils.mapper.gson;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import org.jobrunr.jobs.JobParameter;
import org.jobrunr.utils.reflection.ReflectionUtils;

import java.lang.reflect.Type;

public class JobParameterDeserializer implements JsonDeserializer {

    @Override
    public JobParameter deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) {
        JsonObject jsonObject = jsonElement.getAsJsonObject();
        String jobParameterType = jsonObject.get("className").getAsString();
        return new JobParameter(jobParameterType, deserializeToObject(context, jobParameterType, jsonObject.get("object")));
    }

    private Object deserializeToObject(JsonDeserializationContext context, String type, JsonElement jsonElement) {
        return context.deserialize(jsonElement, ReflectionUtils.toClass(type));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy