Skip to content

Add custom KotlinSerializer for Unit #1046

@ajax-torbin-v

Description

@ajax-torbin-v

Use case

In our company, we provide REST API for users and use reactive Mono as a response for endpoints which return NO_CONTENT.
But in this case, user still see "{ }" as response body, which doesn't correlate with NO_CONTENT status

Describe the solution you'd like

Add new UnitSerializer which will return empty string by default for Unit objects

object UnitSerializer: StdSerializer<Unit>(Unit::class.java) {
    private fun readResolve(): Any = UnitSerializer

    override fun serialize(value: Unit, gen: JsonGenerator, provider: SerializerProvider) =
        gen.writeString("")
}

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions