com.fasterxml.storemate.json.KeySpaceDeserializer 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.*;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;
import com.fasterxml.storemate.api.KeySpace;
@SuppressWarnings("serial")
public class KeySpaceDeserializer extends StdScalarDeserializer
{
public KeySpaceDeserializer() { super(KeySpace.class); }
@Override
public KeySpace deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
switch (jp.getCurrentToken()) {
case VALUE_STRING:
int i = jp.getValueAsInt(-1);
if (i > 0) {
return new KeySpace(jp.getValueAsInt());
}
break;
case VALUE_NUMBER_INT:
return new KeySpace(jp.getIntValue());
default:
}
throw ctxt.mappingException(getValueClass(), jp.getCurrentToken());
}
}