在Android客户端上使用Cloud Endpoint模型中包含的枚举 [英] Using an enum contained in a Cloud Endpoint model on a Android client
问题描述
https://cloud.google.com/developers/articles/google-cloud-endpoints-for-android/
文档说:
关于支持的类型
•枚举。您的后端中的枚举在客户端代码中生成为String表示形式。换句话说,如果您使用后端和客户端的枚举功能,则需要在两个地方定义枚举。
使用
最简单的方法是创建附加模块并将其包含在其他模块中。 / p>
build.gradle
for common
module
应用插件:'java'
依赖关系{
...
}
在此模块中定义您的枚举
。您可以选择所需的任何软件包。
现在在Android应用和后端模块中都包含通用
模块。 / p>
build.gradle
其他模块:
依赖关系{
...
编译项目(':common')
}
这样你只有一个枚举
定义(而不是两个,在不同的模块中,必须手动更新任何一个都改变了)。
I'm trying to implement an enum in a entity called CargoWrapper. In my android app I'm constructing a CargoWrapper object to send to an endpoint method, and then calling my CargoWrapper setters to set the instance varialbes. One of CargoWrappers instance variables is an enum and it's indexed. The only methods generated for my front end are the setter and getters, I can't see the enum. Does anyone know how to set the enum instance variable from a android client, seems like it should be very straight forward?
https://cloud.google.com/developers/articles/google-cloud-endpoints-for-android/
The documentation says: About Supported Types •Enums. Enums in your backend are generated as String representations in the client code. In other words, if you are making use of the enum functionality in both the backend and client, you will need to define the enum in both places.
An example using the enum in the Android client would be great.
The easiest way is to create additional module and include it in other modules.
build.gradle
for common
module
apply plugin: 'java'
dependencies {
...
}
Define your enum
in this module. You can choose whatever package you want.
Now include the common
module in both Android app and backend modules.
build.gradle
for other modules:
dependencies {
...
compile project(':common')
}
This way you have only one enum
definition (instead of two, in different modules, which have to be manually updated when either of them is changed).
这篇关于在Android客户端上使用Cloud Endpoint模型中包含的枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!