3

postコマンドを介してクライアントからサーバーにオブジェクトを送信しています。GSON が返されたときに、返された文字列の最初と最後に誤って引用符が追加されています。

これはコードです:

クライアントコード:

public void getUserRole(){
    Form form = new Form();
    form.add("username", "Testuser");
    form.add("firstname", "Test");
    form.add("lastname", "User");
    form.add("userGroup", "Admin");
    form.add("userGroup", "Normal");

    String userGroupStr = "";

    try {
        userGroupStr = client.post("/rest/login/", "getUserRole", MediaType.APPLICATION_FORM_URLENCODED, String.class, form), 

        //Inspection of userGroupStr  object has role set to: "Admin" when it returns
    }
}

public <T> T post(final String uriExtension, final String path, final String mediaType, final Class<T> returnType,
    final Object postData) {
    return post(uriExtension, path, mediaType, returnType, null, postData);
}

サーバーコード:

@POST
@Path("getUserRole")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@PermitAll
public String getUserRole(@Context HttpServletRequest req,
    @FormParam("username") String username,
    @FormParam("firstname") String firstname,
    @FormParam("lastname") String lastname,
    @FormParam("userGroup") List<String> userGroups) throws Throwable {

    //Stripped out code which essentially sets role to Admin for testing purposes
    String role = "Admin";

    //Inspection of object has role set to: Admin
    return role;
}

誰かがそれを止める方法を教えてくれたら、返されたオブジェクトに余分な引用符を追加していただければ幸いです!!

ありがとう、

4

0 に答える 0