Adapting metadata node to object is returning null | Community
Skip to main content
Level 3
Jan 24, 2018 11:26 AM UTC
Solved

Adapting metadata node to object is returning null

I need to adapt document metadata node to an object. The code is as below. But the object returns null. Did anyone face similar issue?

Resource resource = resourceResolver.getResource(destinationPath+"/"+JcrConstants.JCR_CONTENT+"/metadata");

DocumentInfo documentInfo = resource.adaptTo(DocumentInfo.class);

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
Jan 30, 2018 10:16 PM UTC

Hi,

I don't know the DocumentInfo class, can you please give the full package name? Is there an adapter factory available for this at all? Check localhost:4502/system/console/adapters if an adapter with adapter class "Resource.class" and adaptable class "DocumentInfo.class" is registered.

adaptTo() is allowed to return "null" in case the adaption fails. Depending on the adapter factory the reasons are logged or not. So we clearly need to know much more information about the resource (or sub-resources) you are trying to adapt.

Jörg

11 replies

Level 3
Jan 31, 2018 1:33 PM UTC

Thanks Jorg. I could figure out the issue now. DocumentInfo is a custom class that we have created. We are posting assets to DAM and have additional properties added to metadata.

Currently we are migrating from AEM 6.1 to 6.3. I missed the configuration for making DocumentInfo adaptable. I have added the same and now it is available in "/system/console/adapters" and working as expected.

Translate
joerghoh
joerghohAccepted solution
Employee
Jan 30, 2018 10:16 PM UTC

Hi,

I don't know the DocumentInfo class, can you please give the full package name? Is there an adapter factory available for this at all? Check localhost:4502/system/console/adapters if an adapter with adapter class "Resource.class" and adaptable class "DocumentInfo.class" is registered.

adaptTo() is allowed to return "null" in case the adaption fails. Depending on the adapter factory the reasons are logged or not. So we clearly need to know much more information about the resource (or sub-resources) you are trying to adapt.

Jörg

Translate
smacdonald2008
Level 10
Jan 30, 2018 8:53 PM UTC

Also here is new API to work with assets. Assets HTTP API

Translate
BrijeshYadav
Level 5
Jan 30, 2018 11:50 AM UTC

Hi,

Reason is why you getting null after adopting because the resource you get from path is not Asset or DocumentInfo type its a Node.

Try like this as a Node and use Node api to deal with properties

Resource resource = resourceResolver.getResource(destinationPath+"/"+JcrConstants.JCR_CONTENT+"/metadata");

Node documentNode = resource.adaptTo(Node.class);

or Like this as a proper resource and use respective API.

Resource resource = resourceResolver.getResource(destinationPath);

DocumentInfo documentInfo = resource.adaptTo(DocumentInfo.class);

/Brijesh Yadav

Translate
Level 3
Jan 30, 2018 9:29 AM UTC

Thanks smacdonald2008​. I will wait for the document.

Asset asset = resource.adaptTo(Asset.class);  is also returning null.

Translate
smacdonald2008
Level 10
Jan 29, 2018 8:53 PM UTC

We will start this use case for an article near end of  the week.

Translate
smacdonald2008
Level 10
Jan 29, 2018 3:36 PM UTC

See this thread to get metadata from a DAM asset -

Accessing dam asset metadata programatically

Translate
Level 3
Jan 29, 2018 11:34 AM UTC

Hi,

The mime type is application/pdf.

Thanks,
Anusha

Translate
Level 3
Jan 29, 2018 11:31 AM UTC

Hi smacdonald2008​,

Thanks for the reply. I tried this too, but it doesn't work. Still the object returns null.

Thanks,

Anusha

Translate
smacdonald2008
Level 10
Jan 24, 2018 3:03 PM UTC

We have seen this issue with events. If you are using a System user - try using the Admin call and whitelist the bundle. See if that helps resolve this.

Translate