Expand my Community achievements bar.

Get Multifield List values to Sling Model

Avatar

Level 2

I need Multifield List values to Sling Model class

For single value property we call

@inject

@Named("Author")

@Via("resource")

String authorPath;

But i have property contains String[] that have JSON type, How can i get that values in sling Model class variable 

Can i get like below

@Inject

@Via("resource")

Private List<> authorList;

1 Reply

Avatar

Community Advisor

Dear Brahma,

Kindly refer to the Sling documentation for Sling Models[1].

Notice, section that describes how to create custom annotation on the same page[2]

What it describes, is that you could create a custom annotation for your multi-field list type. Which would parse the data from JCR to your Data model in your preferred way with your own custom logic.

[1] https://sling.apache.org/documentation/bundles/models.html

[2] https://sling.apache.org/documentation/bundles/models.html#custom-annotations

Regards,

Peter