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

com.fasterxml.clustermate.json.StorableKeySerializer Maven / Gradle / Ivy

Go to download

Converters for ClusterMate and StoreMate datatypes, for Jackson-based JSON serialization (as well as other dataformats Jackson supports, like Smile)

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

import java.io.IOException;

import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer;

import com.fasterxml.storemate.shared.StorableKey;
import com.fasterxml.storemate.shared.util.WithBytesCallback;

public class StorableKeySerializer extends StdScalarSerializer
{
    public StorableKeySerializer() {
        super(StorableKey.class);
    }
    
    @Override
    public void serialize(StorableKey value, final JsonGenerator jgen, SerializerProvider provider)
            throws IOException, JsonGenerationException
    {
        IOException e = value.with(new WithBytesCallback() {
            @Override
            public IOException withBytes(byte[] buffer, int offset, int length) {
                try {
                    jgen.writeBinary(buffer, offset, length);
                } catch (IOException e2) {
                    return e2;
                }
                return null;
            }
            
        });
        if (e != null) {
            throw e;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy