开发者

Changing server object representation without updating a client

开发者 https://www.devze.com 2023-03-05 21:47 出处:网络
We have a distributed system in which a 开发者_StackOverflowJava-based server cache communicates with a C# front end, currently through object serialization.

We have a distributed system in which a 开发者_StackOverflowJava-based server cache communicates with a C# front end, currently through object serialization.

One 'nice to have' feature that we've been kicking around for a while is the idea that when the server representation of an object changes, i.e. we add a new attribute, we shouldn't have to release an update for the front-end as well. Right now that's obviously not a possibility - you change the structure of an object, you change its serialized form, and the deserialization doesn't work (or at best captures only what it is used to picking up and no new fields).

I was wondering if anyone had encountered a similar problem before, and what sort of solutions they went through for solving it? One bright spark in the office has suggested we send XML to the client and it should directly build the UI from what is contained within that message - no construction of an object in between - but that of course brings its own problems.

All advice welcome :)

Cheers,

Dave.


you can define a "extra fields" Map<String, Object> as one of the fields in the objects you are planning updates for

however you will still need to tell the client to use it (but it will still be captured even if they don't use it regardless) and new types for the fields can break the front end when the client can't deserialize it


I would probably take a look at google protocol buffers. That protocol supports different protocol versions on the client and server side.


  1. Use a serialization format which is more flexible.
  2. Do not change existing DTO's, extend them

By doing so, the server can send an extended DTO, while the client deserializes the base DTO.

Many serialization frameworks have fields which is marked as optional, which you tag all the new fields with.

0

精彩评论

暂无评论...
验证码 换一张
取 消