com.fasterxml.storemate.json.StorableKeySerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of storemate-json Show documentation
Show all versions of storemate-json Show documentation
Converters for StoreMate datatypes, for Jackson-based JSON serialization
(as well as other dataformats Jackson supports, like Smile)
The newest version!
package com.fasterxml.storemate.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 e) {
return e;
}
return null;
}
});
if (e != null) {
throw e;
}
}
}