Json case: Mapping objects to dictionaries

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Json case: Mapping objects to dictionaries

NorbertHartl
What would be the best software to map my objects to dictionaries? There are a lot of packages in pharo that deal with JSON somehow. But it seems none does mapping from objects to dictionaries and is standalone. We’ve got

- NeoJSON package . Maps objects to strings directly for performance reason
- JSON package. Maps string to JsonObject (subclassed from dictionary)
- Voyage magritte based mapper: Closest to what I find useful but buried inside of Voyage. And I’m not sure it would be easy to factor out this module as a standalone mapper.
- Seaside javascript… : I forgot what it really does. I often shy away looking at it because I don’t want to suck in all the dependencies.

I’m asking because for me this is an important asset. If we talk about JSON there are three things: Objects, JSON structure (being dictionaries and other collections in pharo) and JSON strings. Writing to another server or to a file producing JSON strings seems to be enough. But using it for another system like MongoDB or ElasticSearch this does not work. Here the common interface seems to be dictionaries. With ElasticSearch mapping dictionaries to JSON and MongoDB mapping dictionaries to BSON. So a good descriptive way to map objects to dictionaries would be a good thing to have.

Any thoughts?

Norbert
Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-dev] Json case: Mapping objects to dictionaries

Esteban A. Maringolo
Norbert,

I'm currently building the dictionaries myself. I have a specific
domain class of mapper for each "message" (JSON).
The mapper builder manually builds my domain objects from the
dictionary returned by "JSJsonParser parse: aString", when writing
creates a Dictionary and sends #asJson to it.

E.g. I have a EventBuilder which can build an Event from a JSON string
or viceversa.


I used NeoJSON in the beggining and it's blazing fast (because it is
stream based), but I couldn't get my head around some particular cases
(which I don't remember now, sorry). I WILL give another try, but with
time to fully understand it.

In the Java side of my app, this is one of the simplest things to deal
with, manually to read and write, by using JSONObject and JSONArray,
there's not more of it than this.

Regards,






Esteban A. Maringolo


2013/12/5 Norbert Hartl <[hidden email]>:

> What would be the best software to map my objects to dictionaries? There are a lot of packages in pharo that deal with JSON somehow. But it seems none does mapping from objects to dictionaries and is standalone. We’ve got
>
> - NeoJSON package . Maps objects to strings directly for performance reason
> - JSON package. Maps string to JsonObject (subclassed from dictionary)
> - Voyage magritte based mapper: Closest to what I find useful but buried inside of Voyage. And I’m not sure it would be easy to factor out this module as a standalone mapper.
> - Seaside javascript… : I forgot what it really does. I often shy away looking at it because I don’t want to suck in all the dependencies.
>
> I’m asking because for me this is an important asset. If we talk about JSON there are three things: Objects, JSON structure (being dictionaries and other collections in pharo) and JSON strings. Writing to another server or to a file producing JSON strings seems to be enough. But using it for another system like MongoDB or ElasticSearch this does not work. Here the common interface seems to be dictionaries. With ElasticSearch mapping dictionaries to JSON and MongoDB mapping dictionaries to BSON. So a good descriptive way to map objects to dictionaries would be a good thing to have.
>
> Any thoughts?
>
> Norbert