I've been reading to the article https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling to solve my problem which is :
io.reactivex.exceptions.UndeliverableException: The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling | java.lang.StackOverflowError: stack size 1037KB
        at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:367)
        at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:69)
        at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.lang.StackOverflowError: stack size 1037KB
I know that this StackOverflow is caused by recursive method or function call, been trying to check which method that call itself over and over. Finally, I came up with this solution :
private class CastingDeserializer : StdDeserializer<Casting>(Casting::class.java) {
 override fun deserialize(jp: JsonParser, ctxt: DeserializationContext?): Casting{
            val mappers = jp.codec
            val root = mappers.readTree<JsonNode>(jp)
            val type = root.get("type").asText()
            return if (!type.isNullOrEmpty()){
                mappers.treeToValue(root, getCastingClass(type))
            } else {
                try {
                    Thread.sleep(2000)
                } catch (e: InterruptedException){
                    e.printStackTrace()
                }
                mappers.treeToValue(root, getCastingClass(type))
            }
.....
}
and before I only make the return like this:
return mappers.treeToValue(root, getTransactionClass(type))
This method will be called by :
private val jacksonConverterFactory by lazy {
        val objMapper = ObjectMapper()
                .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
        ..................
        objMapper.registerModule(someModule)
        val castingModule= SimpleModule()
        castingModule.addDeserializer(Casting::class.java, CastingDeserializer())
        objMapper .registerModule(castingModule)
        objMapper .setAnnotationIntrospector(CustomAnnotationInspector())
        objMapper .registerKotlinModule()
        return@lazy JacksonConverterFactory.create(objMapper)
    }
I make a thread for the function to give some delay before calling it again. But I still face the same issue, does anyone know how to implement the proper handling here?, please kindly help me, Thank you
