How do you deal with Evolvability of entities being serialized to/from JSON?

Hey folks, I'm pretty sure this isn't really possible out of the box, but thought I should double check being new to Swift4.

I have a PoC working with Swift4 as a client talking to a backend written in Java using JSON as the exchange format.

The problem we need to resolve is the question of evolvability. For example, the backend may have v2 of the Character entity and the swift client has v1. When the server sends the serialized format of v2, those properties that Swift doesn't know about will be ignored. Thus when the client sends the character entity back to the server, information is lost.

We've solved this in java with a custom serialization format where the entities will implement a custom interface that allows the storage and retrieval of the unhandled/opaque data so that it can be inserted into the serialization stream if present.

Is there any way to achieve something functionally similar with the core Foundation? How are others here dealing with the question of forwards/backwards compatibility?

There are a few solutions that should work and I can suggest:

  • Don't use JSON, but a data structure that takes this into account. e.g. protobufs
  • Have a different model for each version of the API which scope is just to mirror the JSON, and then have your actual business model which contains data in whatever format you want and is able to convert between itself and those

How does the client send the entity back to the server? Do you use REST, or some other protocol? If you use REST, wouldn’t proper PATCH support help? The client would only update the fields it knows about and the rest would be left untouched.

No, we're using gRPC as the transport, so the entire entity will be serialized by the client and returned to the server.