just racked my brain and wasted a few hours, becau...
# ktor
h
just racked my brain and wasted a few hours, because the default json serialization for web sockets and content negotiation uses different default values for encoding defaults. In content negotiation encodedefaults defaults to true and in websockets it defaults to false
a
As I can see, in the Ktor code base the
encodeDefaults
property for all default formats is set to
true
. Сan you describe how to reproduce the inconsistency?
h
you can see here
if i dont include this line it doesnt encode defaults
a
You're right. When you call the
json
method while configuring the
ContentNegotiation
plugin, a predefined
DefaultJson
object is used that has the
encodeDefaults
property set to
true
. When you create an instance of the
KotlinxWebsocketSerializationConverter
, you have to provide your own instance of the format. For consistency, you can use the
DefaultJson
object when creating an instance of
KotlinxWebsocketSerializationConverter
or use a shared instance of the format in both places.
h