Last active
August 29, 2015 14:13
-
-
Save scastrec/56fe2af41a4ecb2edb52 to your computer and use it in GitHub Desktop.
Thrift to Json with Field filter
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
//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