Adapter vs Adaptables w.r.t request.adaptTo(Interface.class) | Community
Skip to main content
Level 2
July 20, 2022

Adapter vs Adaptables w.r.t request.adaptTo(Interface.class)

  • July 20, 2022
  • 2 replies
  • 1013 views

Hi Team , 

 

We have a use -case where in we are using OOTB socialMediahelper.java and socialMediaHelperImpl.java with 1-2 additional fields in it.

So we have used the same logic on our project.  functionality works fine.

But when it comes to its Junits . its fails to request.adaptTo(socialMediahelper.java).

All the time it gives null.

 

-> I debugged it and see adapter and adaptable is getAdapter(adaptable,type) it fails.

final Map<String ,List<AdapterFactoryDescription>> factories = getAdapterFactories(adaptable.getClass());

factories.get(type.getName)); this is giving null and at code print 

log.debug("No Adapter factory found to map {} to  {}, adaptable is slinghttprequest, and type is interface SocialMediaHelper..

 

Same Code as in complete OOTB when I check it works in vanilla instance. 

 

What am I missing here.. what should give as adapter and adaptable to make this succesfull request.adapTo(SocialMediaHelper.class)

 

Please help on this .. 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

B_Sravan
Community Advisor
Community Advisor
July 20, 2022

can you try adapting it to your implementation class?

Level 2
July 20, 2022

Hi Sravan,

 

I did try that same output. : Null I get both the ways shared below.

request.adaptTo(SocialMediaHelper.Class)   or request.adaptTo(SocialMediaHelperImpl.Class) 

 

thanks for your response

Anmol_Bhardwaj
Community Advisor
Community Advisor
July 20, 2022
Level 2
July 20, 2022

Hi Anmol,

I can surely try that.

But as I read the article you shared ,there are still open question and people did say its did not adapt Successfully .. Specially when a OOTB component is extended.