Skip to content

Instantly share code, notes, and snippets.

@dphans
Created April 11, 2018 03:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dphans/5fc563471362d77e3b310f777208fc65 to your computer and use it in GitHub Desktop.
Save dphans/5fc563471362d77e3b310f777208fc65 to your computer and use it in GitHub Desktop.
package com.dinophan.authapp.bases
import com.google.gson.Gson
import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName
import java.io.Serializable
@Suppress("MemberVisibilityCanBePrivate", "RedundantVisibilityModifier")
abstract class BaseModel: Serializable {
@SerializedName("_id")
var _id: Long = -1
@SerializedName("_created_at")
var _created_at: Long = System.currentTimeMillis()
@SerializedName("_updated_at")
var _updated_at: Long = System.currentTimeMillis()
@Expose
var errorMessage: String? = null
open fun validates(): Boolean = true
fun toJson(): String = try {
Gson().toJson(this@BaseModel)
} catch (jsonParsingException: Exception) {
this@BaseModel.errorMessage = jsonParsingException.localizedMessage
"{}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment