JsonApiX is an Android, annotation processor library that was made to transform regular Kotlin classes into their JSON API representations, with the ability to serialize or deserialize them to or from strings.
Now you can have a complete null primary data, like in this example:
@JsonApiX("emptyData", isNullable = true)
@Serializable
class EmptyData : JsonApiModel()
@Serializable
@JsonApiXMeta("emptyData")
data class EmptyDataMeta(val owner: String) : Meta
In this case the EmptyData will act only as wrapper and contains the Meta object or in some cases the Errors object
It also supports have a nullable data class that might be null or not like in this example
@JsonApiX("emptyData", isNullable = true)
@Serializable
data class Student(
val name: String = ""
) : JsonApiModel()
In this case all the data fields should have a default value, And I have wrote a lint rule to check this
This how I achieved this:
In the generated JsonApiX_ I made the data field to be nullable
In case the data is null the type is going to be null, which will stop the JsonApiDiscriminator from working, So used the TypeExtractor to guess the type from the parent data class
Add support for Nullable primary data
Now you can have a complete null primary data, like in this example:
In this case the EmptyData will act only as wrapper and contains the Meta object or in some cases the Errors object
It also supports have a nullable data class that might be null or not like in this example
In this case all the data fields should have a default value, And I have wrote a lint rule to check this
This how I achieved this:
JsonApiX_
I made thedata
field to be nullableJsonApiDiscriminator
from working, So used theTypeExtractor
to guess the type from the parent data class