Expand my Community achievements bar.

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

Avatar

Level 2

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 .. 

4 Replies

Avatar

Community Advisor

can you try adapting it to your implementation class?

Avatar

Level 2

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

Avatar

Level 2

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.