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

io.paradoxical.cassieq.serialization.JacksonJsonMapper Maven / Gradle / Ivy

package io.paradoxical.cassieq.serialization;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.paradoxical.cassieq.model.mappers.Mappers;

import java.io.IOException;


public class JacksonJsonMapper implements JsonMapper {
    private final ObjectMapper mapper;

    public JacksonJsonMapper() {
        this.mapper = Mappers.getJson();
    }

    @Override
    public  String toJson(T item) throws JsonProcessingException {
        return mapper.writeValueAsString(item);
    }

    @Override
    public  T fromJson(String json, Class target) throws IOException {
        if (json == null) {
            return null;
        }

        return mapper.readValue(json, target);
    }

    @Override
    public  T fromJson(final byte[] json, final Class target) throws IOException {
        if (json == null) {
            return null;
        }

        return mapper.readValue(json, target);
    }

    @Override
    public  byte[] toJsonBytes(final T item) throws IOException {
        return mapper.writeValueAsBytes(item);
    }

    public ObjectMapper getMapper() {
        return mapper;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy