Hey everybody, earlier today a asked how could I u...
# announcements
j
Hey everybody, earlier today a asked how could I use data classes and still be able to map the class into an collection of MongoDB using Morphia as ODM and I forgot to say before but just to have a little more of context I'm using Jackson to parse Objects and Jsons so yeah we'll have some
@Json
in the code. So after a while fighting with the code I was able to make things work and as mentioned before I would let you guys know if things work and how it works so check the code down bellow:
Copy code
@Entity
@Indexes(Index(value = "id", fields = arrayOf(Field("id"))))
data class Platform @JsonCreator constructor(@JsonProperty(value = "model") var model:String,
                                         @JsonProperty(value = "latitude") var latitude: Long,
                                         @JsonProperty(value = "longitude") var longitude: Long) {

    @Id
    var id = 0L
    @Property
    lateinit var createdAt: Date
    @Property
    lateinit var updatedAt: Date
    @Reference(concreteClass = CountryProperty::class, idOnly = true, lazy = true)
    var countryPropertyId = 0L
    @Reference(concreteClass = Data::class, idOnly = true, lazy = true)
    lateinit var dataIds: Array<Long>
    @Reference(concreteClass = DataChinese::class, idOnly = true, lazy = true)
    lateinit var dataChineseIds: Array<Long>

    fun isValid(): Boolean {
        return countryPropertyId > 0 && model.isNotBlank()
    }

}
Thank you @groostav and @jjnguy for give some ideas to figure this out!!