If you extend IModel<T>, you’re already extending Serializable, so there’s no need to do any of the things you tried.
The stack trace doesn’t look complete to me. Can you post the full stack trace including line numbers? Also, a reproduce case could be helpful. Thanks, Jon > On Mar 17, 2025, at 4:46 AM, smallufo <small...@gmail.com> wrote: > > private val nameField: TextField<String> = TextField("name", > model.flatMap { m -> LambdaModel.of( { m.name }, { m.name = it } ) }) > > (with wicket 10) > The old code works well with Kotlin 1.9 > But after upgrading kotlin to 2.x > > It shows exception : > private java.lang.Object > org.apache.wicket.MarkupContainer.children[write:1] > [class=org.apache.wicket.markup.html.form.TextField, path=3:form:name] > java.lang.Object org.apache.wicket.Component.data > [class=java.lang.Object] final > org.danekja.java.util.function.serializable.SerializableFunction > org.apache.wicket.model.IModel$4.val$mapper [class=java.lang.Object] > > It seems Kotlin 2 no longer produce serializable lambda. > I tried these ways : > > class SerializableLambdaModel<T>( > private val getter: () -> T, > private val setter: (T) -> Unit > ) : IModel<T>, java.io.Serializable { > > override fun getObject(): T = getter() > > override fun setObject(value: T) { > setter(value) > } > > override fun detach() { > } > } > not working > > and this > > class SerializableLambdaModel<T>( > getter: () -> T, > setter: (T) -> Unit > ) : IModel<T>, java.io.Serializable { > > private val getterFunc: () -> T = object : java.io.Serializable { > override fun toString(): String = getter().toString() > fun get(): T = getter() > } > > private val setterFunc: (T) -> Unit = object : java.io.Serializable { > fun set(value: T) = setter(value) > } > > override fun getObject(): T = getterFunc.get() > > override fun setObject(value: T) { > setterFunc.set(value) > } > > override fun detach() {} > } > > and this > > import org.apache.wicket.model.IModel > import java.io.Serializable > > class SerializableLambdaModel<T : Any?>( > private val getter: () -> T, > private val setter: (T) -> Unit > ) : IModel<T>, Serializable { > > private val getterFunc: SerializableFunction0<T> = > SerializableFunction0(getter) > private val setterFunc: SerializableFunction1<T> = > SerializableFunction1(setter) > > override fun getObject(): T { > return getterFunc.invoke() > } > > override fun setObject(value: T) { > setterFunc.invoke(value) > } > > override fun detach() { > } > > private class SerializableFunction0<T>(private val function: () -> > T) : () -> T, Serializable { > override fun invoke(): T = function() > } > > private class SerializableFunction1<T>(private val function: (T) > -> Unit) : (T) -> Unit, Serializable { > override fun invoke(value: T) = function(value) > } > } > > ALL not working , throws the same error > > Is there any way to solve this ? > > Thanks. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org