仅发布对象的一个​​参数

Only one of the object's parameters is posted

我对 android 开发还很陌生,更不用说 Retrofit 2.0

我正在尝试 POST 数据到本地 API(使用部署),遵循本教程 https://github.com/codepath/android_guides/wiki/Consuming-APIs-with-Retrofit

代码运行后,只贴出对象"user"(用户名)的一个参数,在API.

中可以看到

这是我的服务界面:

public interface serviceInterface{
    String BASE_URL = "http://192.168.0.109:2403";

    @POST("/myojapi")
    Call<User> createUser(@Body User user);

    class myInstance { //just for accessing the methods in the interface

        public static serviceInterface getInstance() {
            Retrofit retrofit = new     Retrofit.Builder().addConverterFactory(GsonConverterFactory.create())
                    .baseUrl(BASE_URL)
                    .build();

            serviceInterface service = retrofit.create(serviceInterface.class);
            service = retrofit.create(serviceInterface.class);
            return service;
        }
    }

    class User {

        @SerializedName("username")
        String uName;

        @SerializedName("password")
        String uPassword;

        public User(String username, String password) {
            this.uName = username;
            this.uPassword = password;
        }

    }
}

这是我的按钮代码,onResponse 方法运行是因为我可以看到 Snackbar 消息(在填写用户名和密码 EditTexts 后):

    button_submit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View v) {
            serviceInterface.User user = new serviceInterface.User(editText_username.getText().toString(), editText_passsword.getText().toString());
            Call<serviceInterface.User> call = serviceInterface.myInstance.getInstance().createUser(user);

            call.enqueue(new Callback<serviceInterface.User>() {
                @Override
                public void onResponse(Call<serviceInterface.User> call, Response<serviceInterface.User> response) {

                    Snackbar.make(v, "added", Snackbar.LENGTH_LONG)
                            .setAction("Action", null).show();
                }

                @Override
                public void onFailure(Call<serviceInterface.User> call, Throwable t) {

                }

            });
        }
    });

这是部署时看到的数据(id是自动的),如你所见,密码总是空的:

这就是 JSON API 的样子:

错误出现在 Deployd 中,密码字段是默认的,它从未显示任何值,创建一个名为 uPassword 的新字段有效。