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

com.fasterxml.clustermate.service.state.JacksonBasedConverter Maven / Gradle / Ivy

There is a newer version: 0.10.5
Show newest version
package com.fasterxml.clustermate.service.state;

import java.io.IOException;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.ObjectWriter;

import com.fasterxml.storemate.shared.util.RawEntryConverter;

public class JacksonBasedConverter
    extends RawEntryConverter
{
    protected final ObjectReader _reader;
    protected final ObjectWriter _writer;

    public JacksonBasedConverter(ObjectMapper mapper, Class type)
    {
        _reader = mapper.reader(type);
        _writer = mapper.writerWithType(type);
    }
    
    @Override
    public T fromRaw(byte[] raw, int offset, int length)
            throws IOException {
        return _reader.readValue(raw, offset, length);
    }

    @Override
    public byte[] toRaw(T value) throws IOException {
        return _writer.writeValueAsBytes(value);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy