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

com.xeiam.xchange.utils.jackson.EnumIntDeserializer Maven / Gradle / Ivy

There is a newer version: 3.1.0
Show newest version
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