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

com.github.lontime.extquartz.impl.JacksonRedissonSerialization Maven / Gradle / Ivy

package com.github.lontime.extquartz.impl;

import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.lontime.extquartz.impl.mixin.CronTriggerMixin;
import com.github.lontime.extquartz.impl.mixin.HolidayCalendarMixin;
import com.github.lontime.extquartz.impl.mixin.JobDetailMixin;
import com.github.lontime.extquartz.impl.mixin.TriggerMixin;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.SimpleTrigger;
import org.quartz.impl.calendar.HolidayCalendar;

/**
 * JacksonRedissonSerialization.
 * @author lontime
 * @since 1.0
 */
public class JacksonRedissonSerialization implements RedissonSerialization {

    private final ObjectMapper mapper;

    public JacksonRedissonSerialization() {
        this.mapper = new ObjectMapper()
                .addMixIn(CronTrigger.class, CronTriggerMixin.class)
                .addMixIn(SimpleTrigger.class, TriggerMixin.class)
                .addMixIn(JobDetail.class, JobDetailMixin.class)
                .addMixIn(HolidayCalendar.class, HolidayCalendarMixin.class)
                .setSerializationInclusion(JsonInclude.Include.NON_NULL);
    }

    @Override
    public Map serializeMap(Object value) {
        return mapper.convertValue(value, new TypeReference>() {});
    }

    @Override
    public  T deserializeMap(Map map, Class clazz) {
        return mapper.convertValue(map, clazz);
    }

    @Override
    public String writeValueAsString(Object value) {
        try {
            return mapper.writeValueAsString(value);
        } catch (JsonProcessingException e) {
            return null;
        }
    }

    @Override
    public  T readValue(String content, Class clazz) {
        try {
            return mapper.readValue(content, clazz);
        } catch (JsonProcessingException e) {
            return null;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy