francescomari / grunt-sling-content

Deploy local content to a Sling instance
MIT License
6 stars 4 forks source link

Implement support for multi-value properties #5

Closed honstar closed 11 years ago

honstar commented 11 years ago

Currently, it is not possible to create nodes having multi-value properties.

Consider following json data:

{ "list": [ "item1": "value1", "item2": "value2" ], "jcr:primaryType": "nt:unstructured" }

A fatal error is thrown: "Fatal error: Arrays are not supported."

francescomari commented 11 years ago

The example you showed is not syntactically correct, I think you meant

{
    "list": ["value1", "value2"],
    "jcr:primaryType": "nt:unstructured"
}

If this is the case, my previous commit solves the problem.

honstar commented 11 years ago

Yes exactly, sorry for the bad example.

honstar commented 11 years ago

Forgot to mention that this works now perfectly. Thanks.

honstar commented 11 years ago

One minor thing to mention though: in case a multi-value property only contains a single item, the resulting property in the repository is not marked as such. This is due to the fact that only a single parameter will be present in the request, thus the Sling POST Servlet cannot know about its multi-value nature.

To enforce this, the @TypeHint parameter with a value of e.g. 'String[]' could help. But then one needs to implement some kind of logic to guess the actual type of the multi-value property.

From a Sling resource API point of view, I think this does not have any functional impact. In case a single-value property is fetched via the ValueMap#get method as array, it returns a single-item array.

francescomari commented 11 years ago

You can include @TypeHint parameters inside the .json descriptor files. Each key in the descriptor will be posted as a form parameter.

In example:

{
    "list": ["value1"],
    "list@TypeHint": "String[]",
    "jcr:primaryType": "nt:unstructured"
}
honstar commented 11 years ago

True, that would work. I forgot that the JSON data basically represents the request parameters for the Sling POST Servlet instead of the real content serialized by the Sling DefaultGetServlet.