views:

40

answers:

2

Hi All,

Is there a way while exposing a web service, I can mark some of the properties in object as immutable or read-only ?

Thanks

A: 

There's nothing special about web services in this regard. If your data object is immutable on the server side, and is deserialised as an immutable class on the client side, then no-one will be able to modify the properties.

What is your motivation for this, though? Making something immutable from the client's perspective is mainly for their convenience rather than any kind of security/correctness from your server's implementation. If they make modifications to their version of an object, it will not affect yours as they are distinct. Thus if your concern is that you want to expose e.g. the server config parameters, without them being able to change them, then simply go ahead - the serialisation/deserialisation process means they get a copy of your object, not a reference to the object itself.

(Note that if you're using remote object sharing such as RMI or Terracotta then the above paragraph may not be true, but then that's not really web services in the classical sense).

Andrzej Doyle
i was looking for some way to not provide consumer with setters for few properties. i want to allow the consumer to edit the object, but certain properties should not be edited. on server i can have my translators do the work, as you also mentioned. but is there any other way ?
Mohit
A: 

I think what you are looking for is not to deserialize all of the members of your classes. If you annotate them properly then some of the members will not be marshalled