Expandir minha barra de realizações na Comunidade.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

Esta conversa foi bloqueada devido à inatividade. Crie uma nova publicação.

SOLUCIONADO

what's the difference between resource.adaptTo(ValueMap.class) and resource.getValueMap()?

Avatar

Level 6

what's the difference between resource.adaptTo(ValueMap.class) and resource.getValueMap()?

1 Solução aceita

Avatar

Resposta correta de
Community Advisor

Hi @Keerthi0555,

The main difference is that adaptTo can return null, so you will have to make sure to implement some null check while using it, to avoid NPE.

getValueMap() method is null safe and will return empty ValueMap in worst case.

In terms of getting ValueMap, you can also check ResourceUtil.getValueMap(resource) that will return empty ValueMap even in the scenario when give resource is null.

Some links for reference:

Ver solução na publicação original

2 Respostas

Avatar

Resposta correta de
Community Advisor

Hi @Keerthi0555,

The main difference is that adaptTo can return null, so you will have to make sure to implement some null check while using it, to avoid NPE.

getValueMap() method is null safe and will return empty ValueMap in worst case.

In terms of getting ValueMap, you can also check ResourceUtil.getValueMap(resource) that will return empty ValueMap even in the scenario when give resource is null.

Some links for reference:

Avatar

Level 6

Thank you .