更改服务器对象表示而不更新客户端
我们有一个分布式系统,其中基于 Java 的服务器缓存与 C# 前端进行通信,当前通过对象序列化进行通信。
我们已经讨论了一段时间的一个“最好有”的功能是这样的想法:当对象的服务器表示发生变化时,即我们添加一个新属性,我们不必发布前端的更新 -也结束。现在这显然是不可能的 - 您更改了对象的结构,更改了其序列化形式,并且反序列化不起作用(或者最多仅捕获用于拾取的内容而没有新字段)。
我想知道以前是否有人遇到过类似的问题,以及他们通过什么样的解决方案来解决这个问题?办公室里的一个聪明人建议我们将 XML 发送给客户端,它应该直接根据该消息中包含的内容构建 UI——中间不构建对象——但这当然会带来自己的问题。
欢迎所有建议:)
干杯,
戴夫。
We have a distributed system in which a Java-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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以定义“额外字段”
Map
作为您计划更新的对象中的字段之一,但是您仍然需要告诉客户端使用它(但它会即使他们不使用它,仍然会被捕获)并且当客户端无法反序列化字段时,字段的新类型可能会破坏前端
you can define a "extra fields"
Map<String, Object>
as one of the fields in the objects you are planning updates forhowever 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.
通过这样做,服务器可以发送扩展的 DTO,而客户端则反序列化基本 DTO。
许多序列化框架都有标记为可选的字段,您可以用它来标记所有新字段。
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.