Skip to content

Instantly share code, notes, and snippets.

@jonathanmv
Last active April 5, 2016 22:22
Show Gist options
  • Save jonathanmv/0f387617f0935834977d5c300f127a7f to your computer and use it in GitHub Desktop.
Save jonathanmv/0f387617f0935834977d5c300f127a7f to your computer and use it in GitHub Desktop.
Takes a json string a returns a thrift object
package jonathanmv.storage;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
public class JsonToThriftConverter {
private JSONObject relationship;
private JSONObject personOne;
private JSONObject personTwo;
public JsonToThriftConverter(String json) throws ParseException {
JSONParser parser = new JSONParser();
this.relationship = (JSONObject) parser.parse(json);
this.personOne = (JSONObject) this.relationship.get("personOne");
this.personTwo = (JSONObject) this.relationship.get("personTwo");
}
public FriendsEdge convert() {
PersonID one = new PersonID();
one.setPerson_id(this.personOne.get("id").toString());
PersonID two = new PersonID();
two.setPerson_id(this.personTwo.get("id").toString());
FriendsEdge friendsEdge = new FriendsEdge();
friendsEdge.setOne(one);
friendsEdge.setTwo(two);
friendsEdge.setTimestamp(this.relationship.get("timestamp").toString());
return friendsEdge;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment