在Android客户端上使用Cloud Endpoint模型中包含的枚举 [英] Using an enum contained in a Cloud Endpoint model on a Android client

查看:148
本文介绍了在Android客户端上使用Cloud Endpoint模型中包含的枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在名为CargoWrapper的实体中实现一个枚举。在我的Android应用程序中,我正在构建一个发送到端点方法的CargoWrapper对象,然后调用我的CargoWrapper设置器来设置实例varialbes。 CargoWrappers实例变量之一是一个枚举,它被索引。为我的前端生成的唯一方法是setter和getter,我看不到枚举。有没有人知道如何从android客户端设置枚举实例变量,似乎应该很直接?



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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆