@JsonDefaultValue<Primitive> -- default values for `value`?
autonomousapps opened this issue · 4 comments
autonomousapps commented
Looking at the following bit of source code:
@Target(AnnotationTarget.VALUE_PARAMETER)
@MustBeDocumented
@Retention(AnnotationRetention.SOURCE)
@JsonDefaultValue
annotation class JsonDefaultValueInt(val value: Int)
Is there any reason it couldn't do the following?
annotation class JsonDefaultValueInt(val value: Int = 0) // default value!
just to reduce a bit of boilerplate.
ansman commented
Well, you can already do this by doing this:
@JsonDefaultValue
val defaultJsonInt: Int = 0
autonomousapps commented
Could you elaborate on that? I have the following:
@JsonSerializable
data class LoginData(
@JsonDefaultValue val login_token: String = "",
@JsonDefaultValue val premium_status: Int = 0,
@JsonDefaultValue val id: Long = 0,
... etc ...
}
And I get errors like:
LoginData.java:79: error: Kotshi: No default value provider found
int premium_status, @se.ansman.kotshi.JsonDefaultValue()
^
ansman commented
@JsonDefaultValue
const val defaultIntValue: Int = 0
@JsonDefaultValue
const val defaultLongValue: Long = 0
@JsonDefaultValue
const val defaultStringValue: String = ""
@JsonSerializable
data class LoginData(
@JsonDefaultValue val login_token: String = "",
@JsonDefaultValue val premium_status: Int = 0,
@JsonDefaultValue val id: Long = 0,
... etc ...
}
autonomousapps commented
Thank you!