infinum / kotlin-jsonapix

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.
Apache License 2.0
38 stars 9 forks source link

Add support for Nullable primary data #51

Closed thisAAY closed 1 year ago

thisAAY commented 1 year ago

Add support for Nullable primary data

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:

sonarcloud[bot] commented 1 year ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication