Skip to content

override modifier in case class parameters causes mayhem #16

@allComputableThings

Description

@allComputableThings
def productToDocument(cc:Product)
    ...
    val values = cc.productIterator
    val fieldList = cc.getClass.getDeclaredFields.toList
    ...
    val purifiedFromId = values.zip(fieldList.iterator).toList.filter { case (v, f) => !isId(f.getName, cc.getClass) }

values and fieldList are not guaranteed to be the same length. Some values may be saved with incorrect field names.

For example:

  class TraceElement3( val date: Int )
  case class LoginEvent3(val userID: Int)
  case class TraceElementLoginEvent3( override val date: Int, val xx:String, val data: LoginEvent3 ) extends TraceElement3(date)

... the overridden value is hidden from the field list (two fields, three values).

Since loading matches fields to the document by case constructor's parameters, one solution to this is to look at the constructor's parameter list fieldList (and their annotations). This would also ensure reading and writing use the same policy to identify fields).

Am working on a fix for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions