sbcgua / ajson

Yet another json parser serializer for ABAP
MIT License
50 stars 15 forks source link

Custom serialization/deserialization of objects #123

Open sbcgua opened 2 years ago

sbcgua commented 2 years ago

ref: #119 (see for code example), @jrodriguez-rc Creating an issue as it might need some discussion.

Custom JSON object. Interface ZIF_AJSON_OBJECT Serializing objects with the interface zif_ajson_object will retrieve the object content at the moment of setting data to zcl_ajson instance.

sbcgua commented 2 years ago

Thoughts ...

interesting idea, but let's unroll it a bit wider.

Naming, I think it can be improved

Design

Deseriazation

mbtools commented 2 years ago

Aside from tracing/debugging, I can't think of a scenario where serializing private attributes makes sense. Do we really need this?

sbcgua commented 2 years ago

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.

jrodriguez-rc commented 2 years ago

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. image

So in the Patient structure resource, I just need to set the reference to the identifier object image

Now, when I serialize the patient resource, it automatically fills the Identifier in the structure I need. image

jrodriguez-rc commented 2 years ago

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.