How to specify a Parse SDK object field name through an annotation?

12 Views Asked by At

How can I specify a Parse object's field name through an annotation? I tried to find the answer on their docs but I had no success.

Reason why I want to do it: Safeness.
I don't want that a var/val rename actually change the "column name".

1

There are 1 best solutions below

0
On

I didn't find a way to do it through an annotation, but I've just realized how we can do it by assembling the Parse model.

The parameter name in attribute() and safeAttribute() allows you to specify a custom name for that field.

Example:

@ParseClassName(value = "Person")
class PersonParseModel : ParseObject() {

    var name: String by attribute(name = "person_name")

    var email: String by attribute(name = "email")

    var profileImageUrl: String? by safeAttribute(name = "profile_image")
}