com.xeiam.xchange.utils.jackson.EnumIntDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xchange-core Show documentation
Show all versions of xchange-core Show documentation
Core functionality used by all other modules.
package com.xeiam.xchange.utils.jackson;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
/**
* @author Matija Mazi
* 0-based enum deserializer. This wil deserialize 0 as the first enum constant, 1 as the second etc.
*/
public abstract class EnumIntDeserializer> extends JsonDeserializer {
private Class enumClass;
protected EnumIntDeserializer(Class enumClass) {
this.enumClass = enumClass;
}
@Override
public E deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
E[] constants = enumClass.getEnumConstants();
return constants[jp.getValueAsInt() + getIndexBase()];
}
protected int getIndexBase() {
return 0;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy