Open sbcgua opened 2 years ago
Thoughts ...
interesting idea, but let's unroll it a bit wider.
Naming, I think it can be improved
zif_ajson_object
-> zif_ajson_serializable
serialize/deserialize
or rehydrate
(but too long imho). Or maybe simply read/write
. so lo_my_object->zif_ajson_serializable~read( ... )
- looks rather understandableDesign
zif_ajson_serializable~read( li_my_json_target )
. Could be a bit better for performance. But exposes existing json content ... so probably no.Deseriazation
{ ... "@object_name": "zcl_blah_blah" }
). It probably won't work with local classes. And construction may require params. Or custom initialization. At the same time interfaces in abap allow static methods, no ? Is it a direction ? Hmmm ...data lo_my ref to zcl_blah.
create object lo_my exporting ...
lo_json->to_abap( changing cv_container = lo_my ).
" OR a new method (though ... very tentative ...)
lo_my ?= lo_json->rehydrate( new zcl_blah( ) ).
zif_ajson_object_factory
and =>instantiate( path = '/A/-/B' )
(where -
stands for array item). But ... then ajson starts to be a gas factory (over complex :)Aside from tracing/debugging, I can't think of a scenario where serializing private attributes makes sense. Do we really need this?
Could be an elegant way to get json representation of objects. E.g. some FI or SD document and you want to send to external service in json.
Or you want to serialize an object (or array of object or ...), send the state to another abap system and rehydrate the objects there. Yet ... this looks a bit far fetched for abap.
Anyway it's just my imagination, I don't have such cases. And I would also like to keep ajson simple (it is already not that simple ... ). So I'd be glad to see the real use case too.
Let me explain what the objective is for me.
I'm working on an FHIR server and my idea is to make a class for each resource and some general elements.
For example, the Patient resource uses the Identifier element which is typical for multiple resources.
So in the Patient structure resource, I just need to set the reference to the identifier object
Now, when I serialize the patient resource, it automatically fills the Identifier in the structure I need.
About the deserialization, I have some doubts about how to do it.
There will be static methods in the interface, but it will lose the possibility of redefinition.
With an instance method we need to instantiate first the object, and then call the method, but the constructor will need parameters.
I like the second option, but a prerequisite for the serializable class will be that the constructor won't have importing parameters.
ref: #119 (see for code example), @jrodriguez-rc Creating an issue as it might need some discussion.