Skip to content

Instantly share code, notes, and snippets.

@scastrec
Last active August 29, 2015 14:13
Show Gist options
  • Save scastrec/56fe2af41a4ecb2edb52 to your computer and use it in GitHub Desktop.
Save scastrec/56fe2af41a4ecb2edb52 to your computer and use it in GitHub Desktop.
Thrift to Json with Field filter
//Solution to convert thrift to pojo to send back to client
// only some fields
public List<JsonObject> mapping(List<TBase> listThrift){
TSerializer serializer = new TSerializer(new TSimpleJSONProtocol.Factory());
ObjectMapper mapper = new ObjectMapper();
for(TBase f : listThrift) {
myJsonList.add(mapper.readValue(serializer.toString(f), MyJsonJson.class));
}
return myJsonList;
}
//JsonObject contains the same wanted fields as my Tbase object
//Solution 2
public class JsonObject {
public JsonObject(MyTBase myTBase){
this.id = myTBase.id;
this.name = myTBase.name;
this.field = myTBase.field;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment