/GsonDeserializer.java Secret
Last active
September 8, 2016 05:01
this json is being used in http://www.myblogspro.com/blog/jeetmp3/2016/8/20/JSON-deserialize-generic-types-using-Gson-and-Jackson
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
import com.google.gson.Gson; | |
import com.google.gson.reflect.TypeToken; | |
public class GsonDeserializer { | |
public static void main(String []args) { | |
Gson gson = new Gson(); | |
GenericResponse<UserResponse> response = gson.fromJson(jsonString, new TypeToken<GenericResponse<UserResponse>>(){}.getType()); | |
System.out.println(response.getData().getName()); | |
System.out.println(response.getData().getEmail()); | |
GenericResponse<SocialAccountsResponse> socialAccountResponse = gson.fromJson(jsonString, new TypeToken<GenericResponse<SocialAccountsResponse>>(){}.getType()); | |
System.out.println(socialAccountResponse.getData().getId()); | |
System.out.println(socialAccountResponse.getData().getProfileUrl()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment