-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Yin wrote:
"the request is about contextual de/serialization.
specifically, there are fields that we want to exclude from
de/serializing in some contexts. one example is the downloadStatus
field, which is useful only on the server. another example is
localLocation, say for cached images, which can have different values
on different users' machines.
the proposal is to have 2 new simpl annotations for a field to specify
applicable contexts, in the form of context names in strings. when
de/serializing, you specify what's the context in the
TranslationContext object, and simpl will determine if the field
should be de/serialized according to the context annotations.
new annotations:
@simpl_context(String[] contextNames): only de/serialize this field
when one of the contextNames is used for the TranslationContext
object.@simpl_no_context(String[] contextNames): do not de/serialize this
field when on of the contextNames is used for the TranslationContext
object.
you can see that they are kinda complementary.
an example:
// in class Document:
@simpl_context("cache") // only de/serialize in the "cache" context
private DownloadStatus downloadStatus;
// at the time of de/serialization outside of caches:
// doc1.downloadStatus is serialized and sent to the client:
Document doc1 = getDoc();
translationContext.addContext("cache"); // here!
msg = serialize(doc1, Format.JSON, translationContext);
sendToClient(msg);
// doc2.downloadStatus does NOT get deserialized in the client:
String msg = recvFromServer();
Document doc2 = deserialize(serializedDocument, Format.JSON,
defaultTranslationContext);the implementation seems straightforward to me. what do you think?"