SlingHttpServletRequest returning null when using Jackson Exporter | Community
Skip to main content
Level 2
May 25, 2021 3:59 PM UTC
Solved

SlingHttpServletRequest returning null when using Jackson Exporter

Hi,

Im using SlingHttpServletRequest in my sling model class with jackson exporter. But the request object is always returning null. Can anyone help me on this.

 

@Model(adaptables = {SlingHttpServletRequest.class,Resource.class}, resourceType = { "sample/components/content/example_comp" }, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
@3484101(name = "jackson", extensions = "json")
public class EESimWizardConfigModel {

 

@586265
SlingHttpServletRequest request;

 

@586265
private HashMap<String, String> productFamilyDetails;

 

public Map<String, String> getProductFamilyDetails() {
         if (request != null) {

             //then do something

         }

 

}

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
joerghoh
joerghohAccepted solution
Employee
May 25, 2021 8:20 PM UTC

The problem is that you allow the model from being adapted from both the request and the resource, and on top of the injected request is optional.

That means, that it is very likely that the behind the scenes the adaption is not done by the request, but rather by the resource, and that the request field is not injected at all.

6 replies

Level 2
May 26, 2021 5:50 AM UTC

@maheswariv26797Can you please try @1961677 private SlingHttpServletRequest request; annotation like this.

 

Translate
Level 4
May 26, 2021 5:47 AM UTC

r

Translate
joerghoh
joerghohAccepted solution
Employee
May 25, 2021 8:20 PM UTC

The problem is that you allow the model from being adapted from both the request and the resource, and on top of the injected request is optional.

That means, that it is very likely that the behind the scenes the adaption is not done by the request, but rather by the resource, and that the request field is not injected at all.

Translate
Asutosh_Jena_
New Participant
May 25, 2021 4:12 PM UTC

Hi @maheswariv26797 

 

Can you try with @SlingObject instead of @Inject once ?

 

@SlingObject

private SlingHttpServletRequest request;

 

http://www.sgaemsolutions.com/2017/06/sling-model-exporter-in-aem-63.html

 

 

Translate
Level 2
May 25, 2021 4:20 PM UTC

Hi @asutosh_jena_,

 

yes,i have used @SlingObject but still it did not work. Am i missing anything?

 

Thanks,

Maheswari

Translate