https://kotlinlang.org logo
#serialization
Title
# serialization
f

Fred Bowker

03/06/2024, 1:41 PM
Hi everyone, I got a surprise that Kotlin serialization doesn’t serialize, defaults values, by default I think it should serialize these values, as it’s kind of unexpected behaviour. Anyone know how I would change
Copy code
@Singleton
class PostServiceWeb
@Inject
constructor(
    properties: AppProperties,
    networkJson: Json,
) : ServiceWeb(
to use a Json that has
Copy code
Json { encodeDefaults = true }
Basically I want to create a default JSON that has this set then it would be injected across the application, or do people change this at the retrofit level, any help would be appreciated
j

jw

03/06/2024, 1:44 PM
Since you are injecting the
Json
instance, find wherever you provide that instance into the dependency graph and replace it with the one you desire.
f

Fred Bowker

03/06/2024, 2:02 PM
Cool, thanks Jake, I’ve got it sorted now
Copy code
@Provides
@Singleton
fun providesNetworkJson(): Json = Json {
    encodeDefaults = true
}