Soriento icon indicating copy to clipboard operation
Soriento copied to clipboard

override modifier in case class parameters causes mayhem

Open allComputableThings opened this issue 8 years ago • 2 comments

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.

allComputableThings avatar Apr 26 '16 01:04 allComputableThings

Is now fixed in my fork.

allComputableThings avatar Apr 27 '16 17:04 allComputableThings

Needs test cases. Will add.

allComputableThings avatar Apr 28 '16 17:04 allComputableThings