You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a class that extends Map[,] but implements its own Json serialization. I just jumped from 2.4.1 to 2.8.3 and I hit an error where its custom serialization doesn't get used. Instead, it attempts to serialize the object based on its Map interface. I expected the JsonSerializable implementation to take priority over any other modules matching the class.
I narrowed down the break to somewhere between tags 2.6.0-rc2 and 2.6.0-rc4. I'll keep looking, but it would be nice if someone might have a direction to point me in. Here's a test class I setup to reproduce the error. It's the one that works in rc2 but fails rc4.
import com.fasterxml.jackson.module.scala.BaseFixture
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.databind.JsonSerializable
import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.jsontype.TypeSerializer
import com.fasterxml.jackson.core.JsonGenerator
class SerializableClass extends Map[String, String] with JsonSerializable {
def +[B1 >: String](kv: (String, B1)) = this
def -(key: String): Map[String,String] = this
// Members declared in scala.collection.MapLike
def get(key: String): Option[String] = None
def iterator: Iterator[(String, String)] = throw new IllegalArgumentException("This shouldn't get called")
override def serialize(jgen:JsonGenerator, provider:SerializerProvider) {
jgen.writeNumber(10)
}
override def serializeWithType(jgen:JsonGenerator, provider:SerializerProvider, typeSer:TypeSerializer) {
serialize(jgen, provider)
}
}
class SerializableTest extends BaseFixture {
it should "use serialize method in JsonSerializable" in { mapper =>
mapper.writeValueAsString(new SerializableClass()) shouldBe "10"
}
}
The text was updated successfully, but these errors were encountered:
Ok good. Although in some ways it'd be nice if jackson-databind could handle it in a way to let custom modules know the special status so that modules did not have to do extra introspection. But conversely it should always be possible to override this behavior (i.e. databind should not automatically assume JsonSerializable implementing things must be handled with default serializer). So I guess this makes most sense for now.
I have a class that extends Map[,] but implements its own Json serialization. I just jumped from 2.4.1 to 2.8.3 and I hit an error where its custom serialization doesn't get used. Instead, it attempts to serialize the object based on its Map interface. I expected the JsonSerializable implementation to take priority over any other modules matching the class.
I narrowed down the break to somewhere between tags 2.6.0-rc2 and 2.6.0-rc4. I'll keep looking, but it would be nice if someone might have a direction to point me in. Here's a test class I setup to reproduce the error. It's the one that works in rc2 but fails rc4.
The text was updated successfully, but these errors were encountered: