java - JacksonMapper to deserialize null value -
i going deserialize json null value java object empty string
i able make custom deserializer, when json value null, did not go deserializer.
how should deserialize it?
thanks in advance!
public class customstringdeserializer extends jsondeserializer<string> { @override public string deserialize(jsonparser jsonparser, deserializationcontext deserializationcontext) throws ioexception, jsonprocessingexception { string str = jsonparser.gettext(); try { return (str == null) ? "" : str; } catch (exception e) { throw new runtimeexception(e); } }
}
public customobjectmapper() { simplemodule _module = new simplemodule("module", new version(1, 9, 10, "final")); _module.adddeserializer(string.class, new customstringdeserializer()); }
thanks @nutlike
i
@override public string getnullvalue() { return ""; }
maybe sufficient overwrite method getnullvalue()?
public class customstringdeserializer extends jsondeserializer<string> { @override public string deserialize(jsonparser jsonparser, deserializationcontext deserializationcontext) throws ioexception, jsonprocessingexception { return jsonparser.gettext(); } @override public string getnullvalue() { return ""; } }
Comments
Post a Comment