IllegalArgumentException:预期原始 class,但得到:class UUID
IllegalArgumentException: expected primitive class, but got: class UUID
我的应用程序正在使用 GAE 端点。我的模型有 UUID。一旦我尝试发送 Android 应用程序,它就会遇到 illegalArgument 异常。
有人建议如何在具有 Google App Engine 端点的 android 应用程序上使用 UUID 处理端点模型吗?
06-14 23:26:49.560 27462-27488/com.example E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
Process: com.example, PID: 27462
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.IllegalArgumentException: key id
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:880)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:381)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:354)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:87)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81)
at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:459)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at com.example.CustomAsyncTask.doInBackground(CustomAsyncTask.java:30)
at com.example.CustomAsyncTask.doInBackground(CustomAsyncTask.java:15)
at android.os.AsyncTask.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.IllegalArgumentException: key id, field private com.example.customApi.model.UUID com.example.customApi.model.Survey.id
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:880)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:471)
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:780)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:381)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:354)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:87)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81)
at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:459)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at com.example.CustomAsyncTask.doInBackground(CustomAsyncTask.java:30)
at com.example.CustomAsyncTask.doInBackground(CustomAsyncTask.java:15)
at android.os.AsyncTask.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.IllegalArgumentException: **expected primitive class, but got: class com.example.customApi.model.UUID**
at com.google.api.client.util.Data.parsePrimitiveValue(Data.java:444)
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:850)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:471)
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:780)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:381)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:354)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:87)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81)
at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:459)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at com.example.CustomAsyncTask.doInBackground(CustomAsyncTask.java:30)
at com.example.CustomAsyncTask.doInBackground(CustomAsyncTask.java:15)
at android.os.AsyncTask.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
我的自定义 class 端点正在返回 Android:
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import java.util.UUID;
@DatabaseTable
public class CustomClass {
@DatabaseField(generatedId = true)
UUID id;
@DatabaseField
String title;
public CustomClass() {
//nothing
}
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
}
我的端点代码:
import java.util.UUID;
import javax.inject.Named;
/**
* An endpoint class we are exposing
*/
@Api(
name = "customApi",
version = "v1",
resource = "customr",
namespace = @ApiNamespace(
ownerDomain = "xyz",
ownerName = "xyz",
packagePath = ""
)
)
public class customClassEndpoint {
@ApiMethod(
name = "insertCustom",
scopes = "profile",
clientIds = {"xx"},
audiences = {"xx"}
)
public CustomClass insertcustomClass(CustomClass customClass, com.google.appengine.api.users.User authUser ) throws ConflictException, OAuthRequestException {
logger.info("Calling insertcustomClass method");
//persisting customClass which assigns UUID
return customClass;
}
}
我确实理解为什么 Google Api JSON 解析器试图将 UUID 解析为原始类型,但至少我找到了解决此问题的方法。
在我的模型中 class 我将字段保留为 UUID 但将 getter 更改为 return 字符串,现在它看起来像这样:
public String getId() {
return id.toString();
}
它已经解决了我的问题。
我的应用程序正在使用 GAE 端点。我的模型有 UUID。一旦我尝试发送 Android 应用程序,它就会遇到 illegalArgument 异常。
有人建议如何在具有 Google App Engine 端点的 android 应用程序上使用 UUID 处理端点模型吗?
06-14 23:26:49.560 27462-27488/com.example E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
Process: com.example, PID: 27462
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.IllegalArgumentException: key id
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:880)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:381)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:354)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:87)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81)
at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:459)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at com.example.CustomAsyncTask.doInBackground(CustomAsyncTask.java:30)
at com.example.CustomAsyncTask.doInBackground(CustomAsyncTask.java:15)
at android.os.AsyncTask.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.IllegalArgumentException: key id, field private com.example.customApi.model.UUID com.example.customApi.model.Survey.id
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:880)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:471)
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:780)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:381)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:354)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:87)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81)
at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:459)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at com.example.CustomAsyncTask.doInBackground(CustomAsyncTask.java:30)
at com.example.CustomAsyncTask.doInBackground(CustomAsyncTask.java:15)
at android.os.AsyncTask.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.IllegalArgumentException: **expected primitive class, but got: class com.example.customApi.model.UUID**
at com.google.api.client.util.Data.parsePrimitiveValue(Data.java:444)
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:850)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:471)
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:780)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:381)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:354)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:87)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81)
at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:459)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at com.example.CustomAsyncTask.doInBackground(CustomAsyncTask.java:30)
at com.example.CustomAsyncTask.doInBackground(CustomAsyncTask.java:15)
at android.os.AsyncTask.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
我的自定义 class 端点正在返回 Android:
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import java.util.UUID;
@DatabaseTable
public class CustomClass {
@DatabaseField(generatedId = true)
UUID id;
@DatabaseField
String title;
public CustomClass() {
//nothing
}
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
}
我的端点代码:
import java.util.UUID;
import javax.inject.Named;
/**
* An endpoint class we are exposing
*/
@Api(
name = "customApi",
version = "v1",
resource = "customr",
namespace = @ApiNamespace(
ownerDomain = "xyz",
ownerName = "xyz",
packagePath = ""
)
)
public class customClassEndpoint {
@ApiMethod(
name = "insertCustom",
scopes = "profile",
clientIds = {"xx"},
audiences = {"xx"}
)
public CustomClass insertcustomClass(CustomClass customClass, com.google.appengine.api.users.User authUser ) throws ConflictException, OAuthRequestException {
logger.info("Calling insertcustomClass method");
//persisting customClass which assigns UUID
return customClass;
}
}
我确实理解为什么 Google Api JSON 解析器试图将 UUID 解析为原始类型,但至少我找到了解决此问题的方法。
在我的模型中 class 我将字段保留为 UUID 但将 getter 更改为 return 字符串,现在它看起来像这样:
public String getId() {
return id.toString();
}
它已经解决了我的问题。