question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to deserialize task data: Failed to deserialize object exception

See original GitHub issue

First, some particulars:

db-scheduler 6.9 Spring Boot 2.1.5.RELEASE PostgresQL 11.6

I have been wrestling with this for a few hours now, but I am stumped. Following the Spring Boot idiom, I have a OneTimeTask defined as a Bean on a TasksConfiguration class (marked with @Configuration) with the signature Task<CountdownTimerTask> countdownTimerTask().

I am able to successfully schedule this task. The task data I supply as an instance of CountdownTimerTask, which implements Serializable and carries a serialVersionUID, serializes just fine.

The task fires as it should and my handler executes, but I get a deserialization exception (as described in the subject line above).

Here are the relevant bits of code (exception-handling has been elided):

(I tried eliminating Lombok and the toString override, just to be pure, but it had no effect).

CountdownTimerTask.java

import lombok.Data;
import java.io.Serializable;

@Data
public class CountdownTimerTask implements Serializable {
    private static final long serialVersionUID = 1L;
    private String projectId;

    @Override
    public String toString() {
        return projectId;
    }
}

TasksConfiguration.java

import com.github.kagkarlsson.scheduler.task.Task;
import com.github.kagkarlsson.scheduler.task.helper.Tasks;
import ***************************.ITwilioService;
import ***************************.CountdownTimerTask;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TasksConfiguration {
    private final ITwilioService twilioService;

    public TasksConfiguration(ITwilioService twilioService) {
        this.twilioService = twilioService;
    }
   
    @Bean
    Task<CountdownTimerTask> countdownTimerTask() {
        return Tasks.oneTime("countdown-timer-task", CountdownTimerTask.class)
                .execute((instance, ctx) -> {
                    this.twilioService.sendSms(new String[] { "**********"}, "Project ID: " + instance.getData().getProjectId());
                });
    }
}

Below is from my service class, which is also the site of the dynamic scheduling of the CountdownTimerTask instance. The transaction event listener fires post-commit, and the handler code executes within the same transaction of the method that published the ProjectCreatedOrUpdatedEvent.

ProjectsService.java

import com.github.kagkarlsson.scheduler.Scheduler;
import com.github.kagkarlsson.scheduler.task.Task;
import ***************************.service.interfaces.IProjectsService;
import ***************************.model.project.*;
import ***************************.model.project.dtos.*;
import ***************************.service.event.ProjectCreatedOrUpdatedEvent;
import ***************************.task.CountdownTimerTask;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.event.TransactionalEventListener;

@TransactionalEventListener
public void processProjectCreatedOrUpdatedEvent(ProjectCreatedOrUpdatedEvent event) 
    throws JsonProcessingException {
        ...

        if (event.getProjectDto().getEarliestBidDeadline() == null) return;

        CountdownTimerTask task = new CountdownTimerTask();
        task.setProjectId(event.getProjectDto().getId());

        scheduler.schedule(countdownTimerTask.instance(
                "countdown-timer-task", task), event.getProjectDto().getEarliestBidDeadline().toInstant());
    }

I’ve got to be missing something here. Also, everything works fine if I don’t involve task data.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

github_iconTop Results From Across the Web

c# - Error when deserializing JSON to Object - Stack Overflow
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is...
Read more >
Failed to deserialize exception from TaskActivity
We are seeing an increasing number of builds failing (after all steps complete successfully) with the following error: Failed to deserialize exception from ......
Read more >
JSON Error when attempting to consume data from an ...
Inner Exception 1: JsonSerializationException: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.
Read more >
Best way to handle JSON deserialization failure in C# : r/csharp
are you perhaps checking for nulls in both the containing object and the property to deserialize? if the extension method is not working...
Read more >
Unable to deserialize process plan from JSON - Flow
with the error on the PowerShell step. If I remove the pill that I pass in to the text function and paste in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found