spring boot - Lombok Getter&Setter not work in bean having custom deserializer -
the issue use lombok annotations @getter , @setter§ beans use parse json files. issue noticed attribute custom deserializer, jackson, not using custom deserializer , error :
for boolean field, true or false recognized
while i'm receiving no false, , yes true.
@jsonproperty(value = "comment") @jsondeserialize(using = noyesdeserializer.class) private boolean comment;
i put annotation on class level : @data , @noargsconstructor
public class noyesdeserializer extends jsondeserializer<boolean> { @override public boolean deserialize(jsonparser p, deserializationcontext ctxt) throws ioexception { if (stringutils.isnotblank(p.gettext())) { string text = p.gettext(); if (text.tolowercase().indexof("yes") >= 0) { return boolean.true; } else if (text.tolowercase().indexof("no") >= 0) { return boolean.false; } } throw new ioexception("unrecognized boolean value " + p.gettext()); } }
Comments
Post a Comment