Android上的Google Cloud Endpoint Illegal Argument异常

时间:2022-03-08 23:50:19

I'm developing an Android application that uses for the back-end an app developed in Google App Engine and the API to that app is developed using Google Cloud Endpoints.

我正在开发一个Android应用程序,该应用程序用于后端使用Google App Engine开发的应用程序,该应用程序的API是使用Google Cloud Endpoints开发的。

I have a method that requires a number of parameters, out of which one is an object. Right now I'm getting an Illegal Argument Exception when doing the call on Android, but this endpoint works on both an iOS app and through the Google API Explorer.

我有一个方法需要许多参数,其中一个是一个对象。现在我在Android上进行调用时遇到非法参数异常,但此端点适用于iOS应用程序和Google API Explorer。

The method definition on the server side is:

服务器端的方法定义是:

@ApiMethod(name="createEvent", httpMethod = HttpMethod.POST)
public EventResponse insertEvent(@Named("creatorId")long creatorId, 
        @Nullable @Named("title")String title, 
        @Nullable @Named("description")String description,
        @Nullable @Named("maxPeople")int max_approved,
        @Named("category")Constants.Category category,
        @Named("latitude")float latitude, 
        @Named("longitude")float longitude, 
        @Nullable @Named("venue") String venue, 
        @Nullable @Named("fromTime")String time, 
        @Nullable @Named("toTime")String toTime, 
        @Nullable @Named("address")String address , 
        @Named("fbToken")String authToken,@Nullable @Named("groupChatId")String groupId,
        @Nullable @Named("dialogId")String dialogId,
        @Nullable @Named("date")String givenDate,
        FriendInvites inviteList,
        @Named("isInviteOnly")boolean isInviteOnly,
        @Nullable @Named("inviteAllWhostrFriends")boolean inviteAllWhostrFriends,
        @Nullable @Named("hashTags")String hashTags
        )

And the call on the Android app is:

Android应用程序上的调用是:

        FriendInvites empty = new FriendInvites();

        List<FacebookInvite> facebookList = new ArrayList<FacebookInvite>();
        empty.setFacebookList(facebookList);

        List<Long> ids = new ArrayList<Long>();
        empty.setWhostrList(ids);

        Eventendpoint.CreateEvent createEvent = service.createEvent(AppState.getInstance().getCurrentUser().getUserId().getId(),
                category, 
                latitude, 
                longitude,
                token, 
                true, 
                empty);

The FriendInvites contains 2 lists:

FriendInvites包含2个列表:

  • A list of Integers
  • 整数列表
  • A list of some other objects.
  • 一些其他对象的列表。

Any ideas about what might be wrong? Might be due to the way the object is serialized?

什么可能是错的?可能是由于对象序列化的方式?

1 个解决方案

#1


0  

In my case apparently it was something weird happening when I added the second boolean variable to the parameter list. I solved the problem by creating a simple wrapper object that contained all the fields required by my method and used that to pass it from the Android client to the server.

在我的情况下,当我将第二个布尔变量添加到参数列表时,显然发生了奇怪的事情。我通过创建一个简单的包装器对象解决了这个问题,该对象包含我的方法所需的所有字段,并用它将它从Android客户端传递到服务器。

#1


0  

In my case apparently it was something weird happening when I added the second boolean variable to the parameter list. I solved the problem by creating a simple wrapper object that contained all the fields required by my method and used that to pass it from the Android client to the server.

在我的情况下,当我将第二个布尔变量添加到参数列表时,显然发生了奇怪的事情。我通过创建一个简单的包装器对象解决了这个问题,该对象包含我的方法所需的所有字段,并用它将它从Android客户端传递到服务器。