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.
In this PR I added the logic to filter out primitive properties of the input model and serialize them in a separate model.
In the output, that model would end up under the attributes key.
Considering that there is a lot of going on in this code I will try to summarize the flow so far, so that the PR would be easier to read :).
Input model get transformed in multiple layer to try to fit the JsonApiWrapper interface.
interface JsonApiWrapper<out Model> {
val data: ResourceObject<Model>?
val errors: List<String>?
}
ResourceObject is a wrapper for all of the JSON API required parameters for a given model.
It contains stuff like: type, id, attributes, relationships, included etc...
interface ResourceObject<out Model> {
val id: String
val type: String
val attributes: AttributesModel?
}
So far, we have managed to account for type, id and attributes. Since type and id are primitive types, there is no issue there, but for the attributes object, we need to create another interface to filter out all of the primitive properties.
No extra action is needed on this interface.
interface AttributesModel
For the filtering properties purposes, Ive used Kotlin Poet Metadata API, and made a custom PropertyTypesSeparator class that handles all the work and outputs 2 lists: primitive props list and composite props list.
I have used the primitives list to populate the AttributesModel generated object and then placed it inside ResourceObject. Next up are the composite types which will be placed under relationships and included objects.
I hope I have explained enough. For any questions, Im always available :)
In this PR I added the logic to filter out primitive properties of the input model and serialize them in a separate model. In the output, that model would end up under the
attributes
key.Considering that there is a lot of going on in this code I will try to summarize the flow so far, so that the PR would be easier to read :).
Input model get transformed in multiple layer to try to fit the
JsonApiWrapper
interface.ResourceObject
is a wrapper for all of the JSON API required parameters for a given model. It contains stuff like:type
,id
,attributes
,relationships
,included
etc...So far, we have managed to account for
type
,id
andattributes
. Sincetype
andid
are primitive types, there is no issue there, but for theattributes
object, we need to create another interface to filter out all of the primitive properties. No extra action is needed on this interface.For the filtering properties purposes, Ive used Kotlin Poet Metadata API, and made a custom
PropertyTypesSeparator
class that handles all the work and outputs 2 lists: primitive props list and composite props list. I have used the primitives list to populate theAttributesModel
generated object and then placed it insideResourceObject
. Next up are the composite types which will be placed underrelationships
andincluded
objects.I hope I have explained enough. For any questions, Im always available :)