Please any one please help. This is My API method
@POST("/user/new.json")
Call createUser(@Body User user);
This is my call in MainActivity
Retrofit retrofit=new Retrofit.Builder().baseUrl("https://XXXXXX.firebaseio.com").addConverterFactory(GsonConverterFactory.create()).build();
Api api=retrofit.create(Api.class);
User user=new User(1,"Sam");
Call<User> call=api.createUser(user);
call.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
Log.d("sam","run");
}
@Override
public void onFailure(Call<User> call, Throwable t) {
Log.d("sam","error");
}
});
This is User.java
public class User {
int id;
String name;
public User(int id, String name) {
this.id = id;
this.name = name;
}
}
Output is coming like that :-
"user" : {"new" : {"-KBgcQTomo8xGpnv5raM" : {"id" : 1,"name" : "Sam"}}}
But i want output like that :-
"user" : {"new" : {"id" : 1,"name" : "Sam"}}
Here is Tutorial For Retrofit + Firebase
please help................
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…