Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best alternative for .NET nullable value type for Java-consumable service

We are creating some WCF services that will initially be consumed by .NET clients but in the future will be consumed to Java clients.

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.

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?

like image 362
Richard Ev Avatar asked Jul 24 '09 07:07

Richard Ev


1 Answers

I'd hope that if you can expose a nullable integer through WCF, that anything consuming that from Java will use the wrapper types - Integer instead of int, Byte instead of byte etc. Of course these are reference types whereas nullable value types in .NET are still value types, so you'll get more GC pressure and it'll be generally less efficient, but there's not a lot you can do about that given that Java doesn't support user-defined value types.

like image 174
Jon Skeet Avatar answered Sep 19 '22 09:09

Jon Skeet