Multiple NeoJSON mappings for the same domain object

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

Multiple NeoJSON mappings for the same domain object

Esteban A. Maringolo
Hi all, Sven, :)

I'm working on a domain model that will have different JSON
representations for the same domain objects, so depending on the
context it will return one representation or another.

In the past to solve the multiple representations, what I did was to
build "helper" methods that added the mappings to the mapper.

So the process was like:
1. instantiate the mapper
2. call a #neoJsonSimple: mapper
3. configure the mapper by calling other mapping defining methods
4. convert the object to a JSON string.

If I wanted an "extended" representation, in the step 2 I would call
#neoJsonExtended: instead.

But I find this "too manual" to scale.

So... is there a better, ¿canonical?, way to achieve this?


Thanks!


ps: By now it will be only object -> JSON (so NeoJSONWriter), but in
the future I might need to instantiate objects back from JSON, so the
mappings should be for both mappers.

Esteban A. Maringolo

Reply | Threaded
Open this post in threaded view
|

Re: Multiple NeoJSON mappings for the same domain object

Esteban A. Maringolo
Meanwhile I found another approach to solve this in the context of a
JSON/REST API.

E.g. see #addRuleToEncode:to:using: in.
https://github.com/ba-st/Stargate/blob/release-candidate/source/Stargate-Examples/PetsRESTfulControllerSpecification.class.st

Has a separate mapper for encoding and decoding, depending on the endpoint:

Regards,

Esteban A. Maringolo

El mar., 12 feb. 2019 a las 19:34, Esteban Maringolo
(<[hidden email]>) escribió:

>
> Hi all, Sven, :)
>
> I'm working on a domain model that will have different JSON
> representations for the same domain objects, so depending on the
> context it will return one representation or another.
>
> In the past to solve the multiple representations, what I did was to
> build "helper" methods that added the mappings to the mapper.
>
> So the process was like:
> 1. instantiate the mapper
> 2. call a #neoJsonSimple: mapper
> 3. configure the mapper by calling other mapping defining methods
> 4. convert the object to a JSON string.
>
> If I wanted an "extended" representation, in the step 2 I would call
> #neoJsonExtended: instead.
>
> But I find this "too manual" to scale.
>
> So... is there a better, ¿canonical?, way to achieve this?
>
>
> Thanks!
>
>
> ps: By now it will be only object -> JSON (so NeoJSONWriter), but in
> the future I might need to instantiate objects back from JSON, so the
> mappings should be for both mappers.
>
> Esteban A. Maringolo

Reply | Threaded
Open this post in threaded view
|

Re: Multiple NeoJSON mappings for the same domain object

NorbertHartl
If you are not in a hurry you can use JSON schema. That is also an external mapper which can validate. And the spec is serializable. You might miss some functionality but I could try to add that if you don‘t do. I would be happy to have more users of the library.

If you use it for REST you could also use OpenAPI which I did. It uses the JSON schema stuff for doing it.

Norbert

> Am 13.02.2019 um 02:58 schrieb Esteban Maringolo <[hidden email]>:
>
> Meanwhile I found another approach to solve this in the context of a
> JSON/REST API.
>
> E.g. see #addRuleToEncode:to:using: in.
> https://github.com/ba-st/Stargate/blob/release-candidate/source/Stargate-Examples/PetsRESTfulControllerSpecification.class.st
>
> Has a separate mapper for encoding and decoding, depending on the endpoint:
>
> Regards,
>
> Esteban A. Maringolo
>
> El mar., 12 feb. 2019 a las 19:34, Esteban Maringolo
> (<[hidden email]>) escribió:
>>
>> Hi all, Sven, :)
>>
>> I'm working on a domain model that will have different JSON
>> representations for the same domain objects, so depending on the
>> context it will return one representation or another.
>>
>> In the past to solve the multiple representations, what I did was to
>> build "helper" methods that added the mappings to the mapper.
>>
>> So the process was like:
>> 1. instantiate the mapper
>> 2. call a #neoJsonSimple: mapper
>> 3. configure the mapper by calling other mapping defining methods
>> 4. convert the object to a JSON string.
>>
>> If I wanted an "extended" representation, in the step 2 I would call
>> #neoJsonExtended: instead.
>>
>> But I find this "too manual" to scale.
>>
>> So... is there a better, ¿canonical?, way to achieve this?
>>
>>
>> Thanks!
>>
>>
>> ps: By now it will be only object -> JSON (so NeoJSONWriter), but in
>> the future I might need to instantiate objects back from JSON, so the
>> mappings should be for both mappers.
>>
>> Esteban A. Maringolo
>


Reply | Threaded
Open this post in threaded view
|

Re: Multiple NeoJSON mappings for the same domain object

NorbertHartl
Forgot to add the links



Norbert

Am 13.02.2019 um 08:44 schrieb Norbert Hartl <[hidden email]>:

If you are not in a hurry you can use JSON schema. That is also an external mapper which can validate. And the spec is serializable. You might miss some functionality but I could try to add that if you don‘t do. I would be happy to have more users of the library.

If you use it for REST you could also use OpenAPI which I did. It uses the JSON schema stuff for doing it.

Norbert

Am 13.02.2019 um 02:58 schrieb Esteban Maringolo <[hidden email]>:

Meanwhile I found another approach to solve this in the context of a
JSON/REST API.

E.g. see #addRuleToEncode:to:using: in.
https://github.com/ba-st/Stargate/blob/release-candidate/source/Stargate-Examples/PetsRESTfulControllerSpecification.class.st

Has a separate mapper for encoding and decoding, depending on the endpoint:

Regards,

Esteban A. Maringolo

El mar., 12 feb. 2019 a las 19:34, Esteban Maringolo
(<[hidden email]>) escribió:

Hi all, Sven, :)

I'm working on a domain model that will have different JSON
representations for the same domain objects, so depending on the
context it will return one representation or another.

In the past to solve the multiple representations, what I did was to
build "helper" methods that added the mappings to the mapper.

So the process was like:
1. instantiate the mapper
2. call a #neoJsonSimple: mapper
3. configure the mapper by calling other mapping defining methods
4. convert the object to a JSON string.

If I wanted an "extended" representation, in the step 2 I would call
#neoJsonExtended: instead.

But I find this "too manual" to scale.

So... is there a better, ¿canonical?, way to achieve this?


Thanks!


ps: By now it will be only object -> JSON (so NeoJSONWriter), but in
the future I might need to instantiate objects back from JSON, so the
mappings should be for both mappers.

Esteban A. Maringolo



Reply | Threaded
Open this post in threaded view
|

Re: Multiple NeoJSON mappings for the same domain object

Sven Van Caekenberghe-2
In reply to this post by Esteban A. Maringolo
Wow, first time I heard about https://github.com/ba-st/Stargate - seems like a great project.

So much is happening in and around Pharo, it is really impossible to follow everything.

> On 13 Feb 2019, at 02:58, Esteban Maringolo <[hidden email]> wrote:
>
> Meanwhile I found another approach to solve this in the context of a
> JSON/REST API.
>
> E.g. see #addRuleToEncode:to:using: in.
> https://github.com/ba-st/Stargate/blob/release-candidate/source/Stargate-Examples/PetsRESTfulControllerSpecification.class.st
>
> Has a separate mapper for encoding and decoding, depending on the endpoint:
>
> Regards,
>
> Esteban A. Maringolo
>
> El mar., 12 feb. 2019 a las 19:34, Esteban Maringolo
> (<[hidden email]>) escribió:
>>
>> Hi all, Sven, :)
>>
>> I'm working on a domain model that will have different JSON
>> representations for the same domain objects, so depending on the
>> context it will return one representation or another.
>>
>> In the past to solve the multiple representations, what I did was to
>> build "helper" methods that added the mappings to the mapper.
>>
>> So the process was like:
>> 1. instantiate the mapper
>> 2. call a #neoJsonSimple: mapper
>> 3. configure the mapper by calling other mapping defining methods
>> 4. convert the object to a JSON string.
>>
>> If I wanted an "extended" representation, in the step 2 I would call
>> #neoJsonExtended: instead.
>>
>> But I find this "too manual" to scale.
>>
>> So... is there a better, ¿canonical?, way to achieve this?
>>
>>
>> Thanks!
>>
>>
>> ps: By now it will be only object -> JSON (so NeoJSONWriter), but in
>> the future I might need to instantiate objects back from JSON, so the
>> mappings should be for both mappers.
>>
>> Esteban A. Maringolo
>


Reply | Threaded
Open this post in threaded view
|

Re: Multiple NeoJSON mappings for the same domain object

Esteban A. Maringolo
In reply to this post by NorbertHartl
Not in a hurry at all, I'm defining this part, so I can explore
different alternatives.

I'll explore the OpenAPI approach with JSONSchema as well.


Regards,

ps: What I liked about Stargate is that it manages other aspects of an
API such as CORS, HATEOAS [1] and resource versioning, but
JSON-HyperSchema [2] seems to provide a similar approach to HATEOAS, I
don't know if there something in OpenAPI to have multiple
representation versions of the same resource (so you preserve the
route, but make the API back AND forward compatible).

[1] https://en.wikipedia.org/wiki/HATEOAS
[2] https://www.ietf.org/archive/id/draft-handrews-json-schema-hyperschema-01.txt

Esteban A. Maringolo

El mié., 13 feb. 2019 a las 4:45, Norbert Hartl (<[hidden email]>) escribió:

>
> If you are not in a hurry you can use JSON schema. That is also an external mapper which can validate. And the spec is serializable. You might miss some functionality but I could try to add that if you don‘t do. I would be happy to have more users of the library.
>
> If you use it for REST you could also use OpenAPI which I did. It uses the JSON schema stuff for doing it.
>
> Norbert
>
> > Am 13.02.2019 um 02:58 schrieb Esteban Maringolo <[hidden email]>:
> >
> > Meanwhile I found another approach to solve this in the context of a
> > JSON/REST API.
> >
> > E.g. see #addRuleToEncode:to:using: in.
> > https://github.com/ba-st/Stargate/blob/release-candidate/source/Stargate-Examples/PetsRESTfulControllerSpecification.class.st
> >
> > Has a separate mapper for encoding and decoding, depending on the endpoint:
> >
> > Regards,
> >
> > Esteban A. Maringolo
> >
> > El mar., 12 feb. 2019 a las 19:34, Esteban Maringolo
> > (<[hidden email]>) escribió:
> >>
> >> Hi all, Sven, :)
> >>
> >> I'm working on a domain model that will have different JSON
> >> representations for the same domain objects, so depending on the
> >> context it will return one representation or another.
> >>
> >> In the past to solve the multiple representations, what I did was to
> >> build "helper" methods that added the mappings to the mapper.
> >>
> >> So the process was like:
> >> 1. instantiate the mapper
> >> 2. call a #neoJsonSimple: mapper
> >> 3. configure the mapper by calling other mapping defining methods
> >> 4. convert the object to a JSON string.
> >>
> >> If I wanted an "extended" representation, in the step 2 I would call
> >> #neoJsonExtended: instead.
> >>
> >> But I find this "too manual" to scale.
> >>
> >> So... is there a better, ¿canonical?, way to achieve this?
> >>
> >>
> >> Thanks!
> >>
> >>
> >> ps: By now it will be only object -> JSON (so NeoJSONWriter), but in
> >> the future I might need to instantiate objects back from JSON, so the
> >> mappings should be for both mappers.
> >>
> >> Esteban A. Maringolo
> >
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Multiple NeoJSON mappings for the same domain object

Esteban A. Maringolo
In reply to this post by Sven Van Caekenberghe-2
Yes, there is a lot going on.

We're still missing a "featured stack" (at least one) that integrates
all the parts of a "common" application need.

"Necessity is the mother of invention" :)

Regards,

Esteban A. Maringolo

El mié., 13 feb. 2019 a las 5:33, Sven Van Caekenberghe
(<[hidden email]>) escribió:

>
> Wow, first time I heard about https://github.com/ba-st/Stargate - seems like a great project.
>
> So much is happening in and around Pharo, it is really impossible to follow everything.
>
> > On 13 Feb 2019, at 02:58, Esteban Maringolo <[hidden email]> wrote:
> >
> > Meanwhile I found another approach to solve this in the context of a
> > JSON/REST API.
> >
> > E.g. see #addRuleToEncode:to:using: in.
> > https://github.com/ba-st/Stargate/blob/release-candidate/source/Stargate-Examples/PetsRESTfulControllerSpecification.class.st
> >
> > Has a separate mapper for encoding and decoding, depending on the endpoint:
> >
> > Regards,
> >
> > Esteban A. Maringolo
> >
> > El mar., 12 feb. 2019 a las 19:34, Esteban Maringolo
> > (<[hidden email]>) escribió:
> >>
> >> Hi all, Sven, :)
> >>
> >> I'm working on a domain model that will have different JSON
> >> representations for the same domain objects, so depending on the
> >> context it will return one representation or another.
> >>
> >> In the past to solve the multiple representations, what I did was to
> >> build "helper" methods that added the mappings to the mapper.
> >>
> >> So the process was like:
> >> 1. instantiate the mapper
> >> 2. call a #neoJsonSimple: mapper
> >> 3. configure the mapper by calling other mapping defining methods
> >> 4. convert the object to a JSON string.
> >>
> >> If I wanted an "extended" representation, in the step 2 I would call
> >> #neoJsonExtended: instead.
> >>
> >> But I find this "too manual" to scale.
> >>
> >> So... is there a better, ¿canonical?, way to achieve this?
> >>
> >>
> >> Thanks!
> >>
> >>
> >> ps: By now it will be only object -> JSON (so NeoJSONWriter), but in
> >> the future I might need to instantiate objects back from JSON, so the
> >> mappings should be for both mappers.
> >>
> >> Esteban A. Maringolo
> >
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Multiple NeoJSON mappings for the same domain object

NorbertHartl
In reply to this post by Esteban A. Maringolo


> Am 13.02.2019 um 13:53 schrieb Esteban Maringolo <[hidden email]>:
>
> Not in a hurry at all, I'm defining this part, so I can explore
> different alternatives.
>
> I'll explore the OpenAPI approach with JSONSchema as well.
>
>
> Regards,
>
> ps: What I liked about Stargate is that it manages other aspects of an
> API such as CORS, HATEOAS [1] and resource versioning, but
> JSON-HyperSchema [2] seems to provide a similar approach to HATEOAS, I
> don't know if there something in OpenAPI to have multiple
> representation versions of the same resource (so you preserve the
> route, but make the API back AND forward compatible).
>
Is there any documentation about stargate? Caring about CORS is surely useful. But I never got why HATEOAS is useful. It adds a lot of complexity with little use.

Norbert

> [1] https://en.wikipedia.org/wiki/HATEOAS
> [2] https://www.ietf.org/archive/id/draft-handrews-json-schema-hyperschema-01.txt
>
> Esteban A. Maringolo
>
>> El mié., 13 feb. 2019 a las 4:45, Norbert Hartl (<[hidden email]>) escribió:
>>
>> If you are not in a hurry you can use JSON schema. That is also an external mapper which can validate. And the spec is serializable. You might miss some functionality but I could try to add that if you don‘t do. I would be happy to have more users of the library.
>>
>> If you use it for REST you could also use OpenAPI which I did. It uses the JSON schema stuff for doing it.
>>
>> Norbert
>>
>>> Am 13.02.2019 um 02:58 schrieb Esteban Maringolo <[hidden email]>:
>>>
>>> Meanwhile I found another approach to solve this in the context of a
>>> JSON/REST API.
>>>
>>> E.g. see #addRuleToEncode:to:using: in.
>>> https://github.com/ba-st/Stargate/blob/release-candidate/source/Stargate-Examples/PetsRESTfulControllerSpecification.class.st
>>>
>>> Has a separate mapper for encoding and decoding, depending on the endpoint:
>>>
>>> Regards,
>>>
>>> Esteban A. Maringolo
>>>
>>> El mar., 12 feb. 2019 a las 19:34, Esteban Maringolo
>>> (<[hidden email]>) escribió:
>>>>
>>>> Hi all, Sven, :)
>>>>
>>>> I'm working on a domain model that will have different JSON
>>>> representations for the same domain objects, so depending on the
>>>> context it will return one representation or another.
>>>>
>>>> In the past to solve the multiple representations, what I did was to
>>>> build "helper" methods that added the mappings to the mapper.
>>>>
>>>> So the process was like:
>>>> 1. instantiate the mapper
>>>> 2. call a #neoJsonSimple: mapper
>>>> 3. configure the mapper by calling other mapping defining methods
>>>> 4. convert the object to a JSON string.
>>>>
>>>> If I wanted an "extended" representation, in the step 2 I would call
>>>> #neoJsonExtended: instead.
>>>>
>>>> But I find this "too manual" to scale.
>>>>
>>>> So... is there a better, ¿canonical?, way to achieve this?
>>>>
>>>>
>>>> Thanks!
>>>>
>>>>
>>>> ps: By now it will be only object -> JSON (so NeoJSONWriter), but in
>>>> the future I might need to instantiate objects back from JSON, so the
>>>> mappings should be for both mappers.
>>>>
>>>> Esteban A. Maringolo
>>>
>>
>>
>


Reply | Threaded
Open this post in threaded view
|

Re: Multiple NeoJSON mappings for the same domain object

Francisco Ortiz Peñaloza
Hi, 

sadly there is no documentation about Stargate yet, we did the first release just 20 days ago. 

Regarding HATEOAS, is an optional feature and we're testing it usefulness right now.

Stargate is built on top of Zinc and Teapot and it has the following features:
- Content negotiation allows serving different representations of a  resource. E.g. "application/json;version=1.0.0" and "application/json;version=1.0.1" serve different representations of a resource. We think this will allow us to grow in easily our APIs.
- Optional resource pagination support.
- Optional HATEOAS support.
- ETag generation.

PS: We already took note of  https://github.com/zweidenker/JSONSchema and https://github.com/zweidenker/OpenAPI. Both projects look great.

On Wed, Feb 13, 2019 at 12:58 PM Norbert Hartl <[hidden email]> wrote:


> Am 13.02.2019 um 13:53 schrieb Esteban Maringolo <[hidden email]>:
>
> Not in a hurry at all, I'm defining this part, so I can explore
> different alternatives.
>
> I'll explore the OpenAPI approach with JSONSchema as well.
>
>
> Regards,
>
> ps: What I liked about Stargate is that it manages other aspects of an
> API such as CORS, HATEOAS [1] and resource versioning, but
> JSON-HyperSchema [2] seems to provide a similar approach to HATEOAS, I
> don't know if there something in OpenAPI to have multiple
> representation versions of the same resource (so you preserve the
> route, but make the API back AND forward compatible).
>
Is there any documentation about stargate? Caring about CORS is surely useful. But I never got why HATEOAS is useful. It adds a lot of complexity with little use.

Norbert
> [1] https://en.wikipedia.org/wiki/HATEOAS
> [2] https://www.ietf.org/archive/id/draft-handrews-json-schema-hyperschema-01.txt
>
> Esteban A. Maringolo
>
>> El mié., 13 feb. 2019 a las 4:45, Norbert Hartl (<[hidden email]>) escribió:
>>
>> If you are not in a hurry you can use JSON schema. That is also an external mapper which can validate. And the spec is serializable. You might miss some functionality but I could try to add that if you don‘t do. I would be happy to have more users of the library.
>>
>> If you use it for REST you could also use OpenAPI which I did. It uses the JSON schema stuff for doing it.
>>
>> Norbert
>>
>>> Am 13.02.2019 um 02:58 schrieb Esteban Maringolo <[hidden email]>:
>>>
>>> Meanwhile I found another approach to solve this in the context of a
>>> JSON/REST API.
>>>
>>> E.g. see #addRuleToEncode:to:using: in.
>>> https://github.com/ba-st/Stargate/blob/release-candidate/source/Stargate-Examples/PetsRESTfulControllerSpecification.class.st
>>>
>>> Has a separate mapper for encoding and decoding, depending on the endpoint:
>>>
>>> Regards,
>>>
>>> Esteban A. Maringolo
>>>
>>> El mar., 12 feb. 2019 a las 19:34, Esteban Maringolo
>>> (<[hidden email]>) escribió:
>>>>
>>>> Hi all, Sven, :)
>>>>
>>>> I'm working on a domain model that will have different JSON
>>>> representations for the same domain objects, so depending on the
>>>> context it will return one representation or another.
>>>>
>>>> In the past to solve the multiple representations, what I did was to
>>>> build "helper" methods that added the mappings to the mapper.
>>>>
>>>> So the process was like:
>>>> 1. instantiate the mapper
>>>> 2. call a #neoJsonSimple: mapper
>>>> 3. configure the mapper by calling other mapping defining methods
>>>> 4. convert the object to a JSON string.
>>>>
>>>> If I wanted an "extended" representation, in the step 2 I would call
>>>> #neoJsonExtended: instead.
>>>>
>>>> But I find this "too manual" to scale.
>>>>
>>>> So... is there a better, ¿canonical?, way to achieve this?
>>>>
>>>>
>>>> Thanks!
>>>>
>>>>
>>>> ps: By now it will be only object -> JSON (so NeoJSONWriter), but in
>>>> the future I might need to instantiate objects back from JSON, so the
>>>> mappings should be for both mappers.
>>>>
>>>> Esteban A. Maringolo
>>>
>>
>>
>