Last active
June 9, 2020 23:42
-
-
Save adrian-cg/1e4d7955d7e220d60b7815eb0b49757b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class JSONUnkownFields { | |
public Map<String,Object> jsonFields; | |
protected abstract void parseKnownFields; | |
public JSONUnkownFields(String jsonString) { | |
jsonFields = (Map<String, Object>)JSON.deserializeUntyped(jsonString); | |
parseKnownFields(); | |
} | |
protected Object getKnownFieldValue(String key) { | |
return jsonFields.remove(key); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UserWrapper extends JSONUNkownFields { | |
public String firstName; | |
public String lastName; | |
public UserWrapper(String jsonString) { | |
super(jsonString); | |
} | |
protected override void parseKnownFields() { | |
firstName = (String)getKnownFieldValue('name'); | |
lastName = (String)getKnownFieldValue('lastName'); | |
} | |
} | |
//new UserWrapper(response.getBody()) .. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment