Logtalk object (de)serialization to JSON?

Help requests on developing Logtalk applications

Moderator: Paulo Moura

Post Reply
JacquesRobin
Posts: 3
Joined: Sat May 23, 2020 8:01 am

Logtalk object (de)serialization to JSON?

Post by JacquesRobin »

Hi,

With two colleagues, we are using Logtalk to implement an AI component inside a complex system cybersecurity framework that follows a service-oriented architecture where Docker containers exchange data through REST APIs. We need to serialize our Logtalk objects to JSON objects to build the payload of the http requests for which our container plays the role of the client and deserialize JSON objects into Logtalk objects to process the payload of the http requests for which our container plays the role of the server.

As we are using the SWI-Prolog implementation of Logtalk, our current idea is to leverage the SWI-Prolog predicates to (de)serialize JSON into SWI-Prolog dictionaries of the SWI-Prolog http library and then write a generic bi-directional converter between Logtalk objects and SWI-Prolog dictionaries. We find this option very legible due to the very high syntactic similarity between JSON and SWI-Prolog dictionaries.

This raises the following questions:
- How to deal with the category imports and the inheritance hierarchies when serializing an object? Should we just add a SWI-Prolog dictionary / JSON key-value pair for every imported and inherited clauses of a Logtalk object into its serialization?
- Would such Logtalk-JSON (de)serialization be valuable for the SWI sub-community of Logtalk beyond our specific need?

Thanks in advance for any insight on those questions.

Paulo Moura
Logtalk developer
Posts: 526
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: Logtalk object (de)serialization to JSON?

Post by Paulo Moura »

JacquesRobin wrote:
Thu Sep 10, 2020 11:10 am
This raises the following questions:
- How to deal with the category imports and the inheritance hierarchies when serializing an object? Should we just add a SWI-Prolog dictionary / JSON key-value pair for every imported and inherited clauses of a Logtalk object into its serialization?
Is exchanging only objects that are the the leafs of the hierarchies feasible? I.e. can the categories and ancestor objects exist in both sides?

Are the objects that you want to exchange "data" objercts? I.e. objects defining facts for predicates declared in some inherited protocol?
JacquesRobin wrote:
Thu Sep 10, 2020 11:10 am
- Would such Logtalk-JSON (de)serialization be valuable for the SWI sub-community of Logtalk beyond our specific need?
I think so. But some of the details may be too application specific to be directly reused. Nevertheless, a public solution would surely help guide others.
Paulo Moura
Logtalk developer

Post Reply