Expand my Community achievements bar.

SOLVED

Getting classCast Exception

Avatar

Level 6

Hi, We have a code snippet,

 

 Map<String, Object> assetMeta = damAsset.getMetadata();
boolean isActiveAsset;

boolean hasOnTime = (assetMeta.get("idam:offTime") != null);
boolean hasOffTime = (assetMeta.get("idam:onTime") != null);

Date offTimeDate = hasOnTime ? ((XMPDateTime) assetMeta.get("idam:offTime")).getCalendar().getTime() : null;
Date onTimeDate = hasOffTime ? ((XMPDateTime) assetMeta.get("idam:onTime")).getCalendar().getTime() : null;


Basically it is getting on and off time of an asset. But the casting in line 5 and 6 is providing class cast exception. Please suggest a way to get rid of the same?
1 Accepted Solution

Avatar

Correct answer by
Employee Advisor
1 Reply

Avatar

Correct answer by
Employee Advisor

hi @akhilraj ,

Check some of the examples of similar case here - https://www.tabnine.com/code/java/methods/com.day.cq.dam.api.Asset/getLastModified