i'm trying to retrieve an inner object from a json response, my json pojo looks like this:
public class Pojo {
private String token;
private User user;
public Pojo()
{}
public Pojo(String username, String password,User user) {
user.setUsername(username);
user.setPassword(password);
this.user = user;
}
public String getToken() {return token;}
public void setToken(String token) {this.token = token;}
public User getUser() {return user;}
public void setUser(User user) {this.user = user;}
and my innerobjct User looks like this:
public class User {
private String username
;
private String name;
private String phone;
private String email;
private String password;
private String is_Active;
}
with their setters and getters
this is my login code:
public void onLogin(View view){
final ProgressDialog dialog = ProgressDialog.show(this, "", "loading...");
EndpointInterface loginService = ServiceAuthGenerator.createService(EndpointInterface.class);
Password = tv_Password.getText().toString();
Username = tv_Username.getText().toString();
User usr = new User();
Pojo user = new Pojo(Username,Password,usr);
Call<Pojo> call = loginService.getToken(usr);
call.enqueue(new Callback<Pojo>() {
#Override
public void onResponse(Response<Pojo> response, Retrofit retrofit) {
dialog.dismiss();
if (response.isSuccess()) {
Pojo user = response.body();
if(user.getUser().getIs_Active()=="True") {
Intent intent = new Intent(getApplicationContext(), MainMenu.class);
startActivity(intent);
}
else{
Toast.makeText(getApplicationContext(), "Wrong User or Password", Toast.LENGTH_SHORT).show();
}
}
}
#Override
public void onFailure(Throwable t) {
dialog.dismiss();
Toast.makeText(getApplicationContext(), "Error Conection", Toast.LENGTH_SHORT).show();
}
});
}
the response is comming like this:
{
"token":"tokengfsgfds"
"user":{
"username":"exmplename"
"email":"#gomail.com"
"is_active":"True"
}
}
i can retrieve the token, but when i try to get variables from the user inner object my app fails. thanks!
this just mirror code for model classes using Gson library
Pojo.java
import com.google.gson.annotations.SerializedName;
public class Pojo {
#SerializedName("token")
private String token;
#SerializedName("user")
private User user;
public Pojo(String username, String password,User user) {
// TODO Auto-generated constructor stub
user.setUsername(username);
user.setPassword(password);
this.token = "tokengfsgfds";
this.user = user;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
take User out of Pojo and make another class User.java
import com.google.gson.annotations.SerializedName;
public class User {
#SerializedName("username")
private String username;
#SerializedName("name")
private String name;
#SerializedName("phone")
private String phone;
#SerializedName("email")
private String email;
#SerializedName("password")
private String password;
#SerializedName("is_Active")
private boolean is_active;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public boolean isIs_active() {
return is_active;
}
public void setIs_active(boolean is_active) {
this.is_active = is_active;
}
}
I used Gson but the output should be the same
import com.google.gson.Gson;
public class TestTwo {
public static void main(String[] args) {
User user = new User();
user.setEmail("someone#gmailcom");
user.setIs_active(true);
user.setName("Cristian");
user.setPassword("Cam");
user.setPhone("1234123441");
user.setUsername("cam.cri");
Pojo pojo = new Pojo("cam.cri", "Cam", user);
String result = (new Gson()).toJson(pojo);
System.out.println(""+result);
Pojo pojo2 = (new Gson()).fromJson(result, Pojo.class);
System.out.println("Token: \t"+pojo2.getToken());
System.out.println("email: \t"+pojo2.getUser().getEmail());
System.out.println("is_active: \t"+pojo2.getUser().isIs_active());
System.out.println("Name: \t"+pojo2.getUser().getName());
System.out.println("Password: \t"+pojo2.getUser().getPassword());
System.out.println("phone: \t"+pojo2.getUser().getPhone());
System.out.println("Username: \t"+pojo2.getUser().getUsername());
}
}
Output
{
"token": "tokengfsgfds",
"user": {
"username": "cam.cri",
"name": "Cristian",
"phone": "1234123441",
"email": "someone#gmailcom",
"password": "Cam",
"is_Active": true
}
}
output
Token: tokengfsgfds
email: someone#gmailcom
is_active: true
Name: Cristian
Password: Cam
phone: 1234123441
Username: cam.cri
Related
I'm following a retrofit course in which I create a small backend with an api in which I have a POST method to perform a teacher's login. In the course what he does is create a teacher and with the set method he passes him the email and the password, which is what this method receives in the API.
I would like to do it in such a way that in the call to Retrofit you pass directly this email and password and I have done it in the following way:
public class LoginActivity extends AppCompatActivity {
private EditText etPasswordLogin, etEmailLogin;
private Button btLogin;
private TextView tvSignUp;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
setupView();
}
private void setupView() {
etPasswordLogin = findViewById(R.id.loginEditTextPassword);
etEmailLogin = findViewById(R.id.loginEditTextEmail);
btLogin = findViewById(R.id.buttonSignUp);
tvSignUp = findViewById(R.id.textViewSignUp);
btLogin.setOnClickListener(v -> userSignUp());
tvSignUp.setOnClickListener(v -> startActivity(new Intent(getApplicationContext(), SignUpActivity.class)));
}
private void userSignUp() {
String email = etEmailLogin.getText().toString().trim();
String password = etPasswordLogin.getText().toString().trim();
if (email.isEmpty()) {
etEmailLogin.setError(getResources().getString(R.string.email_error));
etEmailLogin.requestFocus();
return;
}
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
etEmailLogin.setError(getResources().getString(R.string.email_doesnt_match));
etEmailLogin.requestFocus();
return;
}
if (password.isEmpty()) {
etPasswordLogin.setError(getResources().getString(R.string.password_error));
etPasswordLogin.requestFocus();
return;
}
if (password.length() < 4) {
etPasswordLogin.setError(getResources().getString(R.string.password_error_less_than));
etPasswordLogin.requestFocus();
return;
}
login(email, password);
}
private void login(String email, String password) {
String BASE_URL = "http://10.0.2.2:8040";
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
WebServiceApi api = retrofit.create(WebServiceApi.class);
Call<List<Profesor>> call = api.login(email, password);
call.enqueue(new Callback<List<Profesor>>() {
#Override
public void onResponse(Call<List<Profesor>> call, Response<List<Profesor>> response) {
if (response.code() == 200) {
Log.d("TAG1", "Profesor logeado");
} else if (response.code() == 404) {
Log.d("TAG1", "Profesor no existe");
} else {
Log.d("TAG1", "Error desconocido");
}
}
#Override
public void onFailure(Call<List<Profesor>> call, Throwable t) {
Log.d("TAG Error: ", Objects.requireNonNull(t.getMessage()));
}
});
}
}
And this would be my model teacher:
public class Profesor {
#SerializedName("id")
private Long id;
#SerializedName("nombre")
private String nombre;
#SerializedName("email")
private String email;
#SerializedName("password")
private String password;
#SerializedName("foto")
private String photo;
public Profesor(){}
public Profesor(Long id, String nombre, String email, String photo) {
this.id = id;
this.nombre = nombre;
this.email = email;
this.photo = photo;
}
public Profesor(String email, String password){
this.email = email;
this.password = password;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPhoto() {
return photo;
}
public void setPhoto(String photo) {
this.photo = photo;
}
}
Finally the call to Retrofit that I make is the following:
#FormUrlEncoded
#POST("api/login")
Call<List<Profesor>> login(#Field("email") String email, #Field("password") String password);
However when I run the application and pass through the form the email and password, in the log I return "Error desconocido", however in postman gives me answer without problems:
Any idea what I'm doing wrong?
Your postman request is not a form-urlencoded, but raw.
You need to send a json as a request, and not a field. So to fix this, you may change your API, to handle form-urlencoded requests, or change the Android code this way.
public class LoginCredentials {
#SerializedName("email")
private String email;
#SerializedName("password")
private String password;
public LoginCredentials(String email, String password) {
this.email = email;
this.password = password;
}
}
and change this
#FormUrlEncoded
#POST("api/login")
Call<List<Profesor>> login(#Field("email") String email, #Field("password") String password);
to this
#POST("api/login")
Call<List<Profesor>> login(#Body LoginCredentials credentials);
Hope this will help.
Am using retrofit and RxJava to Connect to API. Data is being successfully posted to Server but i would like to get the Token which the API generates after posting data.
This is for Authentication of user using a JSON Web Token Django Backend
The models are working fine but Here are my Models:
public class User {
#SerializedName("user")
#Expose
private User_ user;
public User_ getUser() {
return user;
}
public void setUser(User_ user) {
this.user = user;
}
#Override
public String toString() {
return new ToStringBuilder(this).append("user", user).toString();
}
}
public class User_ {
#SerializedName("email")
#Expose
private String email;
#SerializedName("password")
#Expose
private String password;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
#Override
public String toString() {
return new ToStringBuilder(this).append("email", email).append("password", password).toString();
}
}
#SerializedName("user")
#Expose
private LoginResponse_ user;
public LoginResponse_ getUser() {
return user;
}
public void setUser(LoginResponse_ user) {
this.user = user;
}
#Override
public String toString() {
return new ToStringBuilder(this).append("user", user).toString();
}
}
public class LoginResponse_ {
#SerializedName("email")
#Expose
private String email;
#SerializedName("token")
#Expose
private String token;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
#Override
public String toString() {
return new ToStringBuilder(this).append("email", email).append("token", token).toString();
}
}
Retrofit Interface
#POST("auth/login")
#Headers("X-Requested-With:XMLHttpRequest")
Observable<User> login(
#Header("Content-Type") String content_type,
#Body User user
);
}
Retrofit Adapter
public class ServiceGenerator {
private static Retrofit retrofit;
private static Gson gson;
public static synchronized Retrofit getUser() {
if (retrofit == null) {
if (gson == null) {
gson = new GsonBuilder().setLenient().create();
}
retrofit = new Retrofit.Builder()
.baseUrl(Constants.BASE_URL)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
}
return retrofit;
}
Retrofit Instance
public class NetworkUtils {
private static UserService userService;
public static UserService ApiInstance(){
if (userService == null){
userService = ServiceGenerator.getUser().create(UserService.class);
}
return userService;
}
}
This is how am trying to login the user
private void loginProcess(String email, String password) {
User user = new User();
User_ user_ = new User_();
user_.setEmail(email);
user_.setPassword(password);
user.setUser(user_);
mUserService.login("application/json", user)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(new Observer<User>() {
#Override
public void onSubscribe(Disposable d) {
}
#Override
public void onNext(User user) {
showResponse(user.toString());
Log.i(TAG, "Response: "+ user);
mProgressBar.setVisibility(View.GONE);
handleResponse();
}
#Override
public void onError(Throwable e) {
e.printStackTrace();
}
#Override
public void onComplete() {
}
});
}
private void handleResponse(LoginResponse response) {
SharedPreferences.Editor editor = mSharedPreference.edit();
editor.putString(Constants.TOKEN,response.getUser().getToken());
editor.putString(Constants.EMAIL,response.getUser().getEmail());
editor.apply();
mEditTextEmail.setText(null);
mEditTextPassword.setText(null);
Intent intent = new Intent(getActivity(),ProfileActivity.class);
startActivity(intent);
}
It would be really helpful if i get to know how to get response after posting the data to the API.
Using postman this is what i post
{"user":{"email":"user#email.com", "password":"userpassword"}}
And this is the response I get
{
"user": {
"email": "user#email.com",
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NSwiZXhwIjoxNTY5MjI5NTgxfQ.S-1yZWNhx_TV8uay8PubGoq9XMpyTIn_ipG8A6DWTfE"
}
}
I am getting the data from the API and then I am converting it to the String so that I can use my POJO classes(User and Token) to save the data into sharedPref. I am able to use the methods of User class but whenever I try to access the method of class Token the app crashes.
Here is my response that I am getting:
{
"username": "string",
"email": "string",
"firstName": "string",
"lastName": "string",
"avatarURL": "string",
"token": {
"token": "string",
"expiresOn": "2019-06-29T21:07:07.891Z"
}}
Here is my User Class:
public class User {
public User() {
}
#SerializedName("username")
#Expose
private String username;
#SerializedName("email")
#Expose
private String email;
#SerializedName("firstName")
#Expose
private String firstName;
#SerializedName("lastName")
#Expose
private String lastName;
#SerializedName("avatarURL")
#Expose
private String avatarURL;
#SerializedName("token")
#Expose
private Token token;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getAvatarURL() {
return avatarURL;
}
public void setAvatarURL(String avatarURL) {
this.avatarURL = avatarURL;
}
public Token getToken() {
return token;
}
public void setToken(Token token) {
this.token = token;
}}
Here is my Token Class:
public class Token {
public Token() {
}
#SerializedName("token")
#Expose
private String token;
#SerializedName("expiresOn")
#Expose
private String expiresOn;
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public String getExpiresOn() {
return expiresOn;
}
public void setExpiresOn(String expiresOn) {
this.expiresOn = expiresOn;
}}
Function from which I am requesting:
public void logInRequest(final String userName, String userPassword) {
final JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("identifier", userName);
jsonObject.put("password", userPassword);
} catch (JSONException e) {
e.printStackTrace();
}
APIService apiService = RetrofitClient.getAPIService();
Call<String> logInResponse = apiService.logIn(jsonObject.toString());
logInResponse.enqueue(new Callback<String>() {
#Override
public void onResponse(Call<String> call, Response<String> response) {
if (response.message().equals("OK")) {
String data = response.body();
Gson g = new Gson();
Gson g1 = new Gson();
User user = g.fromJson(data, User.class);
Token token=g1.fromJson(data,Token.class);
String tokenNo=token.getToken();
String username = user.getUsername();
String email = user.getEmail();
String firstName = user.getFirstName();
String lastName = user.getLastName();
sharedPrefs.saveUserName(username);
sharedPrefs.saveEmail(email);
sharedPrefs.saveFullName(firstName, lastName);
context.startActivity(new Intent(context, HomeActivity.class));
} else {
Toast.makeText(getApplication(), "Wrong User Name or Password", Toast.LENGTH_SHORT).show();
}
}
#Override
public void onFailure(Call<String> call, Throwable t) {
Toast.makeText(getApplication(), "Something went wrong please try again", Toast.LENGTH_SHORT).show();
}
});
}
I have used the inbuilt debugger and the app crashes on this line
Token token=g1.fromJson(data,Token.class);
User user = g.fromJson(data, User.class);
// Try this to get the token of a particular user.
// I think this may be the cause of the error.
Token token = user.getToken();
String tokenNo = token.getToken();
You are trying to 2 different objects to parse the response, but the response is already parsed. If you debug the User object it already contains the Token object inside it. This line is enough:
User user = g.fromJson(data, User.class);
The crash is happening cause you're trying to parse an User JSON object (your data object) into a Token object. So just remove this line:
Token token=g1.fromJson(data,Token.class);
Why the object is returned empty? Android. Retrofit2.
I have a class User:
public class User{
#SerializedName("LOGIN")
String login;
#SerializedName("PASSWORD")
String password;
#SerializedName("NAME")
String name;
#SerializedName("SURNAME")
String surname;
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
}
This's my JSON:
[{
"LOGIN":"TEST",
"PASSWORD":"TEST",
"NAME":"TEST",
"SURNAME":"TEST"
}
]
Interface:
public interface Link {
#GET("93sZY0Xg")
Call<List<User>> listRepos();
}
and class LoginActivity where i use retrofit2:
public class LoginActivity extends AppCompatActivity implements Callback<List<User>>{
private Retrofit retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl("http://pastebin.com/raw/")
.build();
private Link service = retrofit.create(Link.class);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Call<List<User>> us = service.listRepos();
us.enqueue(this);
}
#Override
public void onResponse(Call<List<User>> call, Response<List<User>> response) {
System.out.println(response.body());
System.out.println(response.code());
User us = response.body().get(0);
System.out.println(us.getName());
for(User m: response.body()){
System.out.println( m.getName());
}
}
#Override
public void onFailure(Call<List<User>> call, Throwable t) {
System.out.println(t.getLocalizedMessage());
}
}
I get this response: response.code() is 200;
I/System.out: [com.example.com.dataBase.User#b789a]
I tried getName from class User, but all variables is null.
Why are the values empty? Where's my mistakes?
Try following, expose annotation is important to set value in fields
#Expose
#SerializedName("movie_id")
private String movieId;
#Expose
#SerializedName("movie_name")
private String movieName;
#Expose
#SerializedName("movie_poster")
private String moviePoster;
#Expose
#SerializedName("movie_dialog_count")
private String movieDialogCount;
I am trying to convert the response from server which is a JSON string,I want to convert that JSONstring to java object.I am trying Gson.Please someone explain and tell me the steps how to do it using Gson.
#Override
public void onClick(View v) {
if (v == mLoginButton) {
LoginUser();
}
if (v==mSignUpBtn){
Intent intent=new Intent(LoginActivity.this,RegistrationActivity.class);
startActivity(intent);
}
}
private void LoginUser() {
// final String username = editTextUsername.getText().toString().trim();
final String password = editTextPassword.getText().toString().trim();
final String email = editTextEmail.getText().toString().trim();
StringRequest postStringRequest = new StringRequest(Request.Method.POST,LOGIN_API,
new Response.Listener<String>() {
#Override
public void onResponse(String response) {
Toast.makeText(LoginActivity.this, response, Toast.LENGTH_LONG).show();
Log.d(TAG,"Reponse Check :"+response);
// Gson gson = new Gson();
// String jsonInString = "{}";
//LoginActivity staff = gson.fromJson(jsonInString, LoginActivity.class);
//Log.d(TAG,"Reponse Check staff :"+staff);
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(LoginActivity.this, error.toString(), Toast.LENGTH_LONG).show();
Log.e(TAG,"Error Response Check :"+error);
}
}) {
#Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
Log.d(TAG,"For email :"+email);
Log.d(TAG,"For password :"+password);
//try {
Log.d(TAG,"My Credentials email URL Encoder: "+( mEncryption.AESEncode(email)));
Log.d(TAG,"My Credentials email URL DECODED: "+( mEncryption.AESDecode(mEncryption.AESEncode(email))));
params.put("data[User][email]",(mEncryption.AESEncode(email)));
Log.d(TAG,"My Credentials pass URL Encoder: "+( mEncryption.AESEncode(password)));
paa
}
logcat
03-16 16:36:08.346 2618-3428/com.example.user.myapplication D/Null: For email :abc#gmail.com
03-16 16:36:08.346 2618-3428/com.example.user.myapplication D/Null: For password :12345678
03-16 16:36:08.354 2618-3428/com.example.user.myapplication D/Null: My Credentials email URL Encoder: RyUMRBg7UyeIlFBBtNemZFuG46PJtAIdiZWXnlJ4zNI=
03-16 16:36:08.358 2618-3428/com.example.user.myapplication D/Null: My Credentials email URL DECODED: abc#gmail.com
03-16 16:36:08.360 2618-3428/com.example.user.myapplication D/Null: My Credentials pass URL Encoder: pfrt1fKLkoZhAT6hoMJFiA==
03-16 16:36:08.361 2618-3428/com.example.user.myapplication D/Null: Params :{data[User][password]=pfrt1fKLkoZhAT6hoMJFiA==
, data[User][email]=RyUMRBg7UyeIlFBBtNemZFuG46PJtAIdiZWXnlJ4zNI=
}
03-16 16:36:08.505 2618-2618/com.example.user.myapplication D/Null: Reponse Check :{"code":200,"user":{"User":{"id":"ui1bJkK19jxbaquTboA2oQ==","email":"RyUMRBg7UyeIlFBBtNemZFuG46PJtAIdiZWXnlJ4zNI=","status":"1","verified":"1","created":"2016-03-07 11:41:59","modified":"2016-04-07 15:43:43","token":"6b987332b77d7c69d76bf7be80a85177fb7fa08d"},"Profile":{"id":"1","first_name":"abc","last_name":"fgh","bio":"sfafaf","address":"82, Debinibash Road\r\nDum Dum, P.O. - Motijheel","phone":"+913325505055","profile_pic":"\/img\/356a192b7913b04c54574d18c28d46e6395428ab\/license.jpg","user_id":"1","Contributor":{"id":"31","profile_id":"1","status":"1","vs_cdn_id":"261961777","secret_token":"s-7Va5z","uploaded_on":null,"statement":"AOK KJDHKJDH bkgkg kkhkjh kjhkj kjh kjhkjh","time":"7 hours per month","created":"2016-05-02 18:40:11","modified":"2016-05-02 18:41:29"},"Moderator":[]},"redirect":"\/"}}
You can use in a generic way like:
private final static Gson GSON = new GsonBuilder().create();
public static <T> T fromJSON(String json, Class<T> clazz) {
try {
return GSON.fromJson(json, clazz);
} catch (JsonSyntaxException e) {
LOGGER.warn("Could not deserialize object", e);
}
return null;
}
You can't make activity/fragment from json.
In your onResponse() method:
ModelObject obj = new Gson().fromJson(jsonString, ModelObject.class);
And make ModelObject class something like this:
public class ModelObject {
int field1;
int field2;
//here you should make getters and setters;
}
After it you can do anything you need with this object (pass it to any activity or fragment).
Gson will map the values to the corresponding model class object if the fields are given correctly. Have a look at the below model classes. After that, if you call Example data = GSON.fromJson(yourJson, Example.class); , this data object will have all that you need.
-----------------------------------com.example.Contributor.java-----------------------------------
package com.example;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Contributor {
#SerializedName("id")
#Expose
private String id;
#SerializedName("profile_id")
#Expose
private String profileId;
#SerializedName("status")
#Expose
private String status;
#SerializedName("vs_cdn_id")
#Expose
private String vsCdnId;
#SerializedName("secret_token")
#Expose
private String secretToken;
#SerializedName("uploaded_on")
#Expose
private Object uploadedOn;
#SerializedName("statement")
#Expose
private String statement;
#SerializedName("time")
#Expose
private String time;
#SerializedName("created")
#Expose
private String created;
#SerializedName("modified")
#Expose
private String modified;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getProfileId() {
return profileId;
}
public void setProfileId(String profileId) {
this.profileId = profileId;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getVsCdnId() {
return vsCdnId;
}
public void setVsCdnId(String vsCdnId) {
this.vsCdnId = vsCdnId;
}
public String getSecretToken() {
return secretToken;
}
public void setSecretToken(String secretToken) {
this.secretToken = secretToken;
}
public Object getUploadedOn() {
return uploadedOn;
}
public void setUploadedOn(Object uploadedOn) {
this.uploadedOn = uploadedOn;
}
public String getStatement() {
return statement;
}
public void setStatement(String statement) {
this.statement = statement;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getCreated() {
return created;
}
public void setCreated(String created) {
this.created = created;
}
public String getModified() {
return modified;
}
public void setModified(String modified) {
this.modified = modified;
}
}
-----------------------------------com.example.Example.java-----------------------------------
package com.example;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Example {
#SerializedName("code")
#Expose
private Integer code;
#SerializedName("user")
#Expose
private User user;
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
-----------------------------------com.example.Profile.java-----------------------------------
package com.example;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Profile {
#SerializedName("id")
#Expose
private String id;
#SerializedName("first_name")
#Expose
private String firstName;
#SerializedName("last_name")
#Expose
private String lastName;
#SerializedName("bio")
#Expose
private String bio;
#SerializedName("address")
#Expose
private String address;
#SerializedName("phone")
#Expose
private String phone;
#SerializedName("profile_pic")
#Expose
private String profilePic;
#SerializedName("user_id")
#Expose
private String userId;
#SerializedName("Contributor")
#Expose
private Contributor contributor;
#SerializedName("Moderator")
#Expose
private List<Object> moderator = null;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getBio() {
return bio;
}
public void setBio(String bio) {
this.bio = bio;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getProfilePic() {
return profilePic;
}
public void setProfilePic(String profilePic) {
this.profilePic = profilePic;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public Contributor getContributor() {
return contributor;
}
public void setContributor(Contributor contributor) {
this.contributor = contributor;
}
public List<Object> getModerator() {
return moderator;
}
public void setModerator(List<Object> moderator) {
this.moderator = moderator;
}
}
-----------------------------------com.example.User.java-----------------------------------
package com.example;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class User {
#SerializedName("User")
#Expose
private User_ user;
#SerializedName("Profile")
#Expose
private Profile profile;
#SerializedName("redirect")
#Expose
private String redirect;
public User_ getUser() {
return user;
}
public void setUser(User_ user) {
this.user = user;
}
public Profile getProfile() {
return profile;
}
public void setProfile(Profile profile) {
this.profile = profile;
}
public String getRedirect() {
return redirect;
}
public void setRedirect(String redirect) {
this.redirect = redirect;
}
}
-----------------------------------com.example.User_.java-----------------------------------
package com.example;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class User_ {
#SerializedName("id")
#Expose
private String id;
#SerializedName("email")
#Expose
private String email;
#SerializedName("status")
#Expose
private String status;
#SerializedName("verified")
#Expose
private String verified;
#SerializedName("created")
#Expose
private String created;
#SerializedName("modified")
#Expose
private String modified;
#SerializedName("token")
#Expose
private String token;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getVerified() {
return verified;
}
public void setVerified(String verified) {
this.verified = verified;
}
public String getCreated() {
return created;
}
public void setCreated(String created) {
this.created = created;
}
public String getModified() {
return modified;
}
public void setModified(String modified) {
this.modified = modified;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
}