Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
208 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...