从cassandra读取无效/已折旧的枚举值

r7xajy2e  于 2021-06-09  发布在  Cassandra
关注(0)|答案(0)|浏览(200)

我在数据库中有值north\u west,在对车辆执行选择类时,该值无法Map到枚举值。它给出枚举方向的无效常量north\u west错误。
我不太愿意将north\u west添加为@Discounted,这会进一步混淆开发商/允许其他人滥用价值。
请推荐一些Map程序,允许在将db行转换为java时处理值north\u west。我们使用的是默认的cassandraMap器com.xyz.lib.java.cassandra.dao.basedao.select()

@JsonDeserialize(as = DirectionDeserializer.class)
public enum Direction {
NORTH, 
SOUTH, 
EAST, 
WEST, 
INVALID,//valid ones

NORTH_WEST; //the last one is invalid which was part of the logic for some time in QA but later removed.
}

@Table(name = "vehicle")
public class Vehicle{

@PartitionKey(0)
@Column(name = "id")
String id;

@Column(name = "name")
String name;

@Column(name = "direction")
Direction direction;
}

public class DirectionDeserializer extends StdDeserializer<Direction> {
    public DirectionDeserializer() {
        this(null);
    }
    protected DirectionDeserializer(Class<?> vc) {
        super(vc);
    }
    @Override
    public Direction deserialize(com.fasterxml.jackson.core.JsonParser jsonParser, com.fasterxml.jackson.databind.DeserializationContext deserializationContext) throws IOException, com.fasterxml.jackson.core.JsonProcessingException {
        JsonNode node = jsonParser.getCodec().readTree(jsonParser);
        String value = node.asText();
        if (StringUtils.equalsIgnoreCase(value, "NORTH_WEST")) {
            return Direction.INVALID;
        } else {
            return Direction.valueOf(value);
        }        
}
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题