Expand my Community achievements bar.

SOLVED

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

Avatar

Level 4

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

1 Accepted Solution

Avatar

Correct answer by
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:

View solution in original post

2 Replies

Avatar

Correct answer by
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: