Skip to content

Instantly share code, notes, and snippets.

@adrian-cg
Last active June 9, 2020 23:42
Show Gist options
  • Save adrian-cg/1e4d7955d7e220d60b7815eb0b49757b to your computer and use it in GitHub Desktop.
Save adrian-cg/1e4d7955d7e220d60b7815eb0b49757b to your computer and use it in GitHub Desktop.
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);
}
}
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