用于Java的可消费服务的.NET空值类型最好的选择 [英] Best alternative for .NET nullable value type for Java-consumable service
问题描述
我们正在创造一些将最初由.NET客户端,但在未来会被消耗到Java客户端使用WCF服务。
We are creating some WCF services that will initially be consumed by .NET clients but in the future will be consumed to Java clients.
因此,我们希望避免使用任何类型的数据在该Java不支持的接口。
As such we want to avoid using any data types in the interface that Java does not support.
在特定的一个,我们知道的是空值类型。
The specific one we know of is nullable value types.
一个建议是,我们可以通过使用一个字符串来重新present,例如,可为空INT支持这些。而空字符串,因此重新presents空,否则有要求的字符串必须是可解析为一个int。
One suggestion is that we can support these by using a string to represent, for example, a nullable int. And empty string therefore represents null, otherwise there is a requirement that the string must be parsable as an int.
谁能推荐一个更好的选择,或者是这个你会做什么?
Can anyone recommend a better alternative, or is this what you would do?
推荐答案
这是在我参与了一个几年前(也.NET / Java的组合)的一个项目中使用的一种方法是添加指标性能: NumProperty
和 NumPropertyIsNull
。这是不是特别pretty的,但它的工作。
One approach that was used in a project I was involved in a few years ago (also .NET / Java combination) was to add indicator properties: NumProperty
and NumPropertyIsNull
. It wasn't particularly pretty, but it worked.
作为一个附带节点,我认为最终我们没能找到一个单一的业务情况下的 0
和空的区别
其实重要的。
As a side node, I think that in the end we were not able to find one single business case where the difference between 0
and null
actually mattered.
这篇关于用于Java的可消费服务的.NET空值类型最好的选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!