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

io.automatiko.addons.usertasks.index.fs.JacksonSerializer Maven / Gradle / Ivy

There is a newer version: 0.39.0
Show newest version
package io.automatiko.addons.usertasks.index.fs;

import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping;
import com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
import com.googlecode.cqengine.persistence.support.serialization.PersistenceConfig;
import com.googlecode.cqengine.persistence.support.serialization.PojoSerializer;

import io.quarkus.runtime.annotations.RegisterForReflection;

@RegisterForReflection
public class JacksonSerializer implements PojoSerializer {

    private ObjectMapper mapper;

    public JacksonSerializer(Class objectType, PersistenceConfig persistenceConfig) {
        this();
    }

    public JacksonSerializer() {

        this.mapper = new ObjectMapper();

        mapper.activateDefaultTyping(
                BasicPolymorphicTypeValidator.builder().allowIfSubType(Object.class).build(), DefaultTyping.EVERYTHING,
                As.PROPERTY);

        mapper.registerModule(new ParameterNamesModule())
                .registerModule(new Jdk8Module())
                .registerModule(new JavaTimeModule());
    }

    @Override
    public byte[] serialize(CQEngineUserTaskInfo object) {

        try {
            return mapper.writeValueAsBytes(object);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public CQEngineUserTaskInfo deserialize(byte[] bytes) {
        try {
            return mapper.readValue(bytes, CQEngineUserTaskInfo.class);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy