Hey , i have created json and i am trying to adapt resource to my sling model class. I have created the json correctly using .json on the browser with all fields of component dialog populated , however when i give resource path till the component my adapted sling model returns null . If i update the resource path to anything inside the component in json , i get an adapted sling model with null values for the fields inside (which is expected since the path is wrong).
My issue here is why is not adapting when i give correct path till the component in json . Is there something that i might be missing?
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
You can debug your Junit to see why the Sling Model has not been adopted. Check if there is any logic inside the @Postconstruct method of your Sling Model.
There is logic within the post construct actually, so what do i have to do in this regard? The post construct method is retrieving a list of of child items present in dialog multifield and assigning to an array
Hi @Zendarkke
Please check example here : https://github.com/arunpatidar02/com.aemlab.junitapp/blob/master/core/src/test/java/com/aemlab/junit...
There are other sling models as well, you can check those as well : https://github.com/arunpatidar02/com.aemlab.junitapp/tree/master/core/src/test
@Zendarkke : Can you please share the code snippet of how you are resolving the resource. Also, if possible the resource json.
Hi,
The reason this is failing is that the "resource" (loaded through your JSON) does not meet all the requirements expected by your Sling model. You should check the following aspects of your Sling model:
A good way to figure out what is going on is to use the SlingModelFactory
to create the Sling model instead of adapting it from the resource. This approach will provide a more informative error message about what failed during the model creation. Something like this:
MyModel model = context.getService(ModelFactory.class).createModel(request, MyModel.class);
Hope this helps.
@Zendarkke Did you find the suggestions helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!
Views
Replies
Total Likes