com.yahoo.vespa.flags.JacksonArraySerializer Maven / Gradle / Ivy
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.flags;
import com.fasterxml.jackson.databind.JavaType;
import java.util.List;
import java.util.function.Predicate;
/**
* @author freva
*/
public class JacksonArraySerializer implements FlagSerializer> {
private final JavaType type;
private final Predicate> validator;
public JacksonArraySerializer(Class clazz, Predicate> validator) {
type = JsonNodeRawFlag.constructCollectionType(List.class, clazz);
this.validator = validator;
}
@Override
public List deserialize(RawFlag rawFlag) {
var list = JsonNodeRawFlag.fromJsonNode(rawFlag.asJsonNode()).>toJacksonClass(type);
if (!validator.test(list)) {
throw new IllegalArgumentException("Invalid value: " + list);
}
return list;
}
@Override
public RawFlag serialize(List value) {
return JsonNodeRawFlag.fromJacksonClass(value);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy