我剛剛開始使用Google Cloud Endpoints, 我使用Python構建了一個API,甚至需要在Android Studio/Gradle環境中使用生成的源代碼。Google Cloud Endpoints:Android客戶端中的NumberFormatException當響應包含DateTime字段
我面臨一個問題,即每當來自Cloud Endpoints的響應包含DateTime對象時,都會引發NumberFormatException。
08-05 13:27:28.143 32116-32141/com.dgt.ds E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.IllegalArgumentException: [key created_at, field private com.google.api.client.util.DateTime com.google.api.services.dsApi.model.ServicesDResponse.createdAt]
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:797)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:438)
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:745)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:358)
at com.google.api.client.json.JsonParser.parse(JsonParser.java:331)
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.dgt.ds.MainActivity$1.doInBackground(MainActivity.java:70)
at com.dgt.ds.MainActivity$1.doInBackground(MainActivity.java:58)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
... 5 more
Caused by: java.lang.NumberFormatException: Invalid date/time format: 2013-08-05T10:27:27.449810
at com.google.api.client.util.DateTime.parseRfc3339(DateTime.java:301)
at com.google.api.client.util.Data.parsePrimitiveValue(Data.java:435)
at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:795)
... 17 more
這是在Python的消息對象(我使用message_types.DateTimeField
):
class DResponse(messages.Message):
id = messages.StringField(1)
created_at = message_types.DateTimeField(2)
author = messages.StringField(3)
description = messages.StringField(4, required=True)
我怎樣才能解決這個問題?
它可能是一個錯誤,無論是'DateTimeField'實現方式還是Java客戶端庫中。對於相同的請求,JSON負載看起來如何?您可以通過https:// yourappid.appspot.com/_ah/api/explorer訪問您的應用程序的API瀏覽器進行測試。 – bossylobster
@bossylobster它看起來像一個正確的JSON響應,DateTimeField是'「created_at」:「2013-08-05T10:27:27.449000」' –
謝謝,我會做更多的挖掘。 – bossylobster