Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

org.apache.sling.event.impl.jobs.JobManagerImpl Discarding job - properties must be serializable: job/topic

Avatar

Level 2

Hello,

 

I am getting an exception when processing DamEvent events on my Job manager that implements EventHandler. I am using code guidelines from  references below. My code works fine when processing PageEvent but it does not process the job for DamEvent.

 
public static final String JOB_TOPIC = "aem/solr/indexing/job";
final Map<String, Object> payload = new HashMap<String, Object>();
DamEvent damEvent = DamEvent.fromEvent(event);
payload.put("damEvent", damEvent);
jobManager.addJob(JOB_TOPIC, payload); 
 
** It works when using PageEvent pageEvent = PageEvent.fromEvent(event);
 
In the error log I see this exception on DamEvent events:

the 23.06.2023 16:43:12.938 *WARN* [EventAdminThread #20] org.apache.sling.event.impl.jobs.JobManagerImpl Discarding job - properties must be serializable: aem/solr/indexing/job : {damEvent=com.day.cq.dam.api.DamEvent@733fc832}

 

I see this note in the Sling documentation which I don't quite understand: "The job topic follows the conventions for the topic of an OSGi event. All objects in the payload must be serializable and publically available (exported by a bundle). This is required as the job is persisted and unmarshalled before processing.

Also, I see there is a checkJob in the API (https://github.com/apache/sling-org-apache-sling-event/blob/master/src/main/java/org/apache/sling/ev...) which describes the exception I am getting. 

 

Is this a bug? I am working on AEM 6.5.15.0 

 

References:

https://sling.apache.org/documentation/bundles/apache-sling-eventing-and-job-handling.html

https://sling.apache.org/documentation/tutorials-how-tos/how-to-manage-events-in-sling.html

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
3 Replies

Avatar

Correct answer by
Community Advisor

By default objects on aem are not serialized and your payload need to be serialized as explained on https://sling.apache.org/documentation/bundles/apache-sling-eventing-and-job-handling.html

you need to deserialized your payload object(damevent)as explained https://helpx.adobe.com/experience-manager/kb/deserialization-not-allowed-error.html

 

https://www.linkedin.com/pulse/aem-sling-jobs-processed-nurbek-umirov

Avatar

Community Advisor

Hello @Lucas_Reyes - 

 

As per the Apache Sling documentation

 

All objects in the payload of a job must be serializable. This is because the job is persisted and unmarshalled before processing. Serialization allows the objects to be converted into a format that can be stored and reconstructed later.

 

Issue : You are trying to add it directly to the payload using payload.put("damEvent", damEvent);. However, the DamEvent class might not implement the Serializable interface, causing the serialization error.

 

 

import java.io.Serializable;

public class CustomDamEventData implements Serializable {
    // Define necessary fields to hold the extracted information from DamEvent
    private String eventId;
    private String eventPath;
    
    // Constructors, getters, and setters for the fields
    // ...

    @Override
    public String toString() {
        return "CustomDamEventData{" +
                "eventId='" + eventId + '\'' +
                ", eventPath='" + eventPath + '\'' +
                '}';
    }
}

 

 

 

Avatar

Level 2

Thank you for your replies DPrakashRaj and Tanika02.

 

I was missing the fact that DamEvent does not implement Serializable, but DamEvent.Type does. So a little bit of refactoring fixed my issue while sending the payload:

DamEvent damEvent = DamEvent.fromEvent(event);
payload.put("eventType"damEvent.getType());
payload.put("assetPath"damEvent.getAssetPath());
 
Thank you!