Task not serializable: java.io.NotSerializableException when calling function in Serializable class

Viewed 18

I have a class which is Serializable

class GetTaxResilience extends Serializable {
    private val logger = LoggerFactory.getLogger(this.getClass)

    val retryConfig = RetryConfig.custom()
        .maxAttempts(RESILIENCE_RETRY_MAX_ATTEMPTS)
        .retryExceptions(classOf[StatusRuntimeException])
        .retryOnException(asJavaPredicate(exception => exception.isInstanceOf[StatusRuntimeException]))
        .intervalFunction(IntervalFunction.ofRandomized(RESILIENCE_RETRY_INTERVAL_MILLISECONDS))
        .build

    val retryRegistry = RetryRegistry.of(retryConfig)

    val retryInstance = retryRegistry.retry(GET_VERTEX_TAX_RETRY_DEFAULT_NAME, retryConfig)

    def getDefaultRetryInstance(): Retry = {
        // default retry instance configured in yaml
        logger.info("Retrieving default retry instance: {}", GET_VERTEX_TAX_RETRY_DEFAULT_NAME)
        retryInstance
    }
}

In my main function, I'm calling getDefaultRetryInstance function

class mainClass extends Serializable{
  @Autowired
    var getTaxResilience: GetTaxResilience = null
    getTaxResilience.getDefaultRetryInstance()

//get error at this line 
           calculateResultDF.write.mode(SaveMode.Overwrite).insertInto(sqlTableHelper.VERTEX_CALCULATE_RESULT_TABLE)

}

but I got error

Task not serializable: java.io.NotSerializableException: java.util.function.Predicate$$Lambda$310/1296833449
App > Serialization stack:
App >   - object not serializable (class: java.util.function.Predicate$$Lambda$310/1296833449, value: java.util.function.Predicate$$Lambda$310/1296833449@6e15fe26)
App >   - field (class: io.github.resilience4j.retry.RetryConfig, name: exceptionPredicate, type: interface java.util.function.Predicate)
App >   - object (class io.github.resilience4j.retry.RetryConfig, io.github.resilience4j.retry.RetryConfig@1f4ca8b5)
App >   - field (class: determination.resilience.GetTaxResilience, name: retryConfig, type: class io.github.resilience4j.retry.RetryConfig)
...

it said "io.github.resilience4j.retry.RetryConfig, name: exceptionPredicate, type: interface java.util.function.Predicate" is not Serializable, but this class already implements Serializable.

public class RetryConfig implements Serializable {}

how can I fix this issue?

0 Answers
Related