Ronald Barrera
Ronald Barrera

Reputation: 43

Moshi Retrofit Request

I'm doing a POST request and I'm using @JsonClass(generateAdapter = true)

And the request body is as follow:

{
    "request": "some data",
    "data": {}
}

When creating my data class, how could I declare the empty object "data" = {}

My data class is as follow:

@JsonClass(generateAdapter = true)
data class Request(val request: String, val data: ?)

But, how could I create the empty body?

Upvotes: 0

Views: 352

Answers (1)

Alex Maryin
Alex Maryin

Reputation: 21

Your data should be nullable type of necessary class with 'null' default value, so like:

@JsonClass(generateAdapter = true)
data class Request(val request: String, val data: MyData? = null)

I think it will works.

Upvotes: 0

Related Questions