com.geotab.model.serialization.DtcClassDeserializer Maven / Gradle / Ivy
package com.geotab.model.serialization;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.geotab.model.enumeration.DtcClass;
import java.io.IOException;
/**
* Custom {@link DtcClass} deserializer, which returns {@link DtcClass#UNCLASSIFIED} as default if
* the json value is not recognized.
*/
public class DtcClassDeserializer extends JsonDeserializer {
@Override
public DtcClass deserialize(JsonParser jsonParser,
DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
return DtcClass.findOrDefault(jsonParser.getValueAsString());
}
}