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

SlingHttpServletRequest returning null when using Jackson Exporter

  • May 25, 2021
  • 4 replies
  • 2684 views

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.
Best answer by joerghoh

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.

4 replies

Asutosh_Jena_
Community Advisor
Community Advisor
May 25, 2021

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

 

 

Level 2
May 25, 2021

Hi @asutosh_jena_,

 

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

 

Thanks,

Maheswari

joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
May 25, 2021

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.

Level 4
May 26, 2021

r

Level 2
May 26, 2021

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