java - Can jackson deserialize from different JSON string to same object? -
i have json string, this:
{ ... "token": "abc123" ... }
then reason, have update new structure, expected incoming json string becomes:
{ ... "token": {"property01":"true", "property02":"false", "value": "abc123"} ... }
originally, token field in string type, now, becomes object, additional properties.
i need handle both format backward compatibility, can jackson handle case?
you creating own deserializer:
class foojsondeserializer extends jsondeserializer<foo> { @override public foo deserialize(jsonparser jp, deserializationcontext ctxt) throws ioexception, jsonprocessingexception { foo foo = new foo(); //deserialize data here return foo; } }
and don't forget add deserializer class
@jsondeserialize(using = foojsondeserializer.class) class foo { ... }
Comments
Post a Comment