Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

402
Visualizações
How to ignore a filed of Entity with Room

I have a data class that I created an Entity from that for my database.

this is my data class:

@Entity
@Parcelize
data class Tapligh(

    @PrimaryKey(autoGenerate = true)
    var id: Long,

    @SerializedName("title") var title: String?,
    @SerializedName("type") var type: Int?,
    @SerializedName("os") var os: Int?,
    @SerializedName("logo") var logo: String?,
    @SerializedName("template") var template: String?,
    @SerializedName("action") var action: String?,
    @SerializedName("date") var date: String?,
    @Embedded
    @SerializedName("videos") var videos: Videos?,

) : Parcelable {

    fun getTaplighType(): Int {

        return when (this.type) {

            0 -> TaplighType.IMAGE.type
            1 -> TaplighType.VIDEO.type
            else -> TaplighType.NATIVE.type
        }
    }
}

@Parcelize
data class Videos(

    @SerializedName("land") var land: String?,
    @SerializedName("port") var port: String?
) : Parcelable

Now by adding below field into my Tapligh data class, I will get an error:

 @Ignore
 @SerializedName("images") var images: List<String>?

I am getting this error:

error: Entities and Pojos must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).
public final class Tapligh implements android.os.Parcelable {
             ^
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

@Ignore in Kotlin classes requires default parameter value and @JvmOverloads annotation:

data class Tapligh  @JvmOverloads constructor(
    ...

    @Ignore
    @SerializedName("images") var images: List<String>? = null
)
over 4 years ago · Santiago Trujillo Relatório

0

Sometimes new field create an error when class implements Parcelable, so try to remove Parcelable and body of class, put Parcelable and implement members again or just implement Serializable interface instead of Parcelable.

over 4 years ago · Santiago Trujillo Relatório

0

The provided Taplight has errors:

@PrimaryKey(autoGenerate = true) var id: Long,
@SerializedName("title") var title: String?,
@SerializedName("type") var type: Int?,
@SerializedName("os") var os: Int?,
@SerializedName("logo") var logo: String?,
@SerializedName("template") var template: String?,
@SerializedName("action") var action: String?,
@SerializedName("date") var date: String?,
@Embedded
@SerializedName("videos") var videos: Videos?) {

constructor() : this(0,null,null,null,null,null,null,null,null)

videos seems like the last argument and the constructor was badly called. I don't know if that was a copy-paste or formatting error, but hope it could help.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda