You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Nicolas Peltier <np...@adobe.com> on 2016/04/19 18:11:23 UTC

[import] how to POST ordered structures

Hi,

json objects’ key values are not ordered, so does that mean there is no choice but to use xml to POST ordered structure?

Thanks,
Nicolas

Re: [import] how to POST ordered structures

Posted by Nicolas Peltier <np...@adobe.com>.
xml hurts, would it be acceptable to have a “internal” key in object that specifies the order?

> On 19 Apr 2016, at 18:11, Nicolas Peltier <np...@adobe.com> wrote:
> 
> Hi,
> 
> json objects’ key values are not ordered, so does that mean there is no choice but to use xml to POST ordered structure?
> 
> Thanks,
> Nicolas


Re: [import] how to POST ordered structures

Posted by Nicolas Peltier <np...@adobe.com>.
Thanks Bertrand,

just tracked https://issues.apache.org/jira/browse/SLING-5682
> On 20 Apr 2016, at 14:53, Bertrand Delacretaz <bd...@apache.org> wrote:
> 
> {
>    "title": "The parent node",
>    "SLING:ordered": [{
>        "SLING:name": "first",
>        "title": "This comes first"
>    }, {
>        "SLING:name": "second",
>        "title": "This comes second"
>    }]
> }
> 
> This needs to be triggered by selector or content-type switch so that
> the existing POST behavior is unchanged.
> 
> I suppose having SLING:ordered should then also set the appropriate
> mixin on the parent node.


Re: [import] how to POST ordered structures

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Wed, Apr 20, 2016 at 2:17 PM, Nicolas Peltier <np...@adobe.com> wrote:
>>...the alternative being to extend the POST servlet to do what
>> you need, as it's generally useful.
> right, how would you see it? custom key value like “slingpost_order”:[“child1”,”child2”,”child3”] ? ...

That won't scale if you have many objects, how about submitting
content as a json array, maybe something like this:

{
    "title": "The parent node",
    "SLING:ordered": [{
        "SLING:name": "first",
        "title": "This comes first"
    }, {
        "SLING:name": "second",
        "title": "This comes second"
    }]
}

This needs to be triggered by selector or content-type switch so that
the existing POST behavior is unchanged.

I suppose having SLING:ordered should then also set the appropriate
mixin on the parent node.

-Bertrand

Re: [import] how to POST ordered structures

Posted by Nicolas Peltier <np...@adobe.com>.
> 
> OOTB yes, the alternative being to extend the POST servlet to do what
> you need, as it's generally useful.
right, how would you see it? custom key value like “slingpost_order”:[“child1”,”child2”,”child3”] ?


> 
> -Bertrand


Re: [import] how to POST ordered structures

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Nicolas,

On Wed, Apr 20, 2016 at 11:11 AM, Nicolas Peltier <np...@adobe.com> wrote:
> ...so to me ootb i have 2 choices...

OOTB yes, the alternative being to extend the POST servlet to do what
you need, as it's generally useful.

-Bertrand

Re: [import] how to POST ordered structures

Posted by Nicolas Peltier <np...@adobe.com>.
Hi,

i don’t see how with current api [0] i could inject an array for child nodes (would miss the child node name, and the parent type)
so to me ootb i have 2 choices (not sure of the one i dislike the most):
- xml import as i’m already using json in my client jar, so adding another lib just for that is a pity,
- doing 2 POST, second for ordering (not even sure i can do that in one POST), as i want to minimize the request #

[0] curl -F ":operation=import" -F":contentType=json" -F:"name=sample" -F":content=…”

> On 20 Apr 2016, at 11:01, Bertrand Delacretaz <bd...@apache.org> wrote:
> 
> Hi,
> 
> On Tue, Apr 19, 2016 at 6:11 PM, Nicolas Peltier <np...@adobe.com> wrote:
>> json objects’ key values are not ordered, so does that mean there is no choice
>> but to use xml to POST ordered structure?...
> 
> Could you use arrays instead of objects in your POST requests to keep ordering?
> 
> I don't remember how our default POST servlet or content loader handle
> that so you might need to experiment.
> 
> Similarly, our json GET servlet [1] uses an .harray selector to switch
> to arrays instead of objects to keep ordering.
> 
> -Bertrand
> 
> [1] https://sling.apache.org/documentation/bundles/rendering-content-default-get-servlets.html#default-json-rendering


Re: [import] how to POST ordered structures

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Tue, Apr 19, 2016 at 6:11 PM, Nicolas Peltier <np...@adobe.com> wrote:
> json objects’ key values are not ordered, so does that mean there is no choice
> but to use xml to POST ordered structure?...

Could you use arrays instead of objects in your POST requests to keep ordering?

I don't remember how our default POST servlet or content loader handle
that so you might need to experiment.

Similarly, our json GET servlet [1] uses an .harray selector to switch
to arrays instead of objects to keep ordering.

-Bertrand

[1] https://sling.apache.org/documentation/bundles/rendering-content-default-get-servlets.html#default-json-rendering