Java Web 服务自定义返回类型
我有这样的困境。
我正在开发一个网络服务。 它必须返回支持的语言列表。 语言存储在枚举中。
是返回(从 Web 方法)枚举数组还是将其转换为字符串并返回字符串数组更好。
也许我更喜欢字符串数组,这样客户端就不必处理自定义对象类型,并且不需要序列化/反序列化。但另一方面,如果我在客户端需要该枚举,我将不得不重新实现它并将字符串数组转换回枚举数组。
你有什么建议?
I have this dilemma.
I'm developing a web services.
It has to return a list of supported languages.
Languages are stored in an enum.
Is it better to return (from web method) an enum array or covert it to string and return a string array.
Maybe I'd prefer string array so the client doesn't have to mess with custom object types, and no serialization/deserialization is required. But on the other hand, if I need that enum on the client I'll have to reimplement it and convert the string array back to enum array.
What do you suggest?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通常经验法则应该是“尽可能简单”。因为我在 WSDL 生成客户时看到过非常有趣的事情。
Usually the thumb rule should be Keep It As Simple As Possible . Because i have seen really funny things happen with WSDLs while generating their clients.
像往常一样:这取决于:)
你已经回答了你自己的问题,我想说..
客户端是否需要自定义对象才能对其进行任何操作?使用自定义对象来实现它。
字符串表示足够吗?去做吧..
我不知道有关该主题的任何指导方针..
As usual: it depends :)
You have already answered your own question I'd say..
Does the client need the custom object in order to do any operations with it? Implement it with a custom object.
Is the String representation sufficient? Go for that..
I don't know of any guidelines regarding that topic..
我同意。我认为服务应该尽可能封装和独立。无论如何,我不喜欢任何类型的自动生成。另外,我更喜欢 REST 和纯 HTTP,而不是 WS 和 SOAP。尽管我会保留这两个选项。
所以我想我会继续使用简单的字符串数组返回。至少如果没有人给我强有力的理由不这样做:)
I agree. I believe services should be encapsulated and independent as much as possible. Anyway I'm not a big fan of any kind of auto-generation. Also I prefer REST and pure HTTP over WS and SOAP. Although I will leave both options available.
So I think I'll just stay with simple string array return. At least if nobody gives me a strong argument not to :)