Serialization and nested classes

38 views
Skip to first unread message

and...@vandebron.nl

unread,
Feb 3, 2016, 10:49:08 AM2/3/16
to scala-salat
Hello everyone, i'm currently facing a weird behavior in my application as i can't serialize a case class for (apparently) various reason.I have a polymorphic queue-like implementation where each class extends "AbstractQueueItem" 
@Salat
abstract class AbstractQueueItem(
  @Key("_id") val id: Option[ObjectId],
  val creationDate: LocalDateTime = new LocalDateTime(),
  val status: ItemStatusEnum.Value = ItemStatusEnum.Unprocessed,
  val response: Option[String] = None) {
  def clone(newStatus: ItemStatusEnum.Value, newResponse: Option[String] = None): AbstractQueueItem
}
I already have a couple of classes extending it and it all works properly except for this new one : 
case class MeterReadingRequestQueueItem(
  override val id: Option[ObjectId] = None,
  override val creationDate: LocalDateTime = new LocalDateTime(),
  override val status: ItemStatusEnum.Value = ItemStatusEnum.Unprocessed,
  override val response: Option[String] = None,
  request: MeterReadingsRequest
) extends AbstractQueueItem(id, creationDate, status, response) {
  def clone(newStatus: ItemStatusEnum.Value, newResponse: Option[String] = None): AbstractQueueItem = this.copy(status = newStatus, response = newResponse)
}
Now the request is the interesting part and it is as follow: 

case class MeterReadingsRequest(
  reference: Long,
  readings: MeterReadingSubmission
)
case class MeterReadingSubmission(
CaseId: String,
ContactCaseId: Option[String],
Comment: String,
MeterReadingMethod: Option[String],
ReadingDate: Option[String] = None,
MeterReadingRequests: List[MeterReadingRequest]
)
case class MeterReadingRequest(
ReadingDate: String,
Digits: Option[Int],
EAN: String,
LDNT1: Option[Int],
LDNT2: Option[Int],
ODNT1: Option[Int],
ODNT2: Option[Int]
)

Odd enough the ReadingDate is a Option[String] or just String in the case of the inner request and that is because the serialization was just failing saying (can't serialize class org.joda.time.LocalDateTime
java.lang.IllegalArgumentException: can't serialize class org.joda.time.LocalDateTime
at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:299))

While trying to track down the issue i changed the LocalDateTime into plain string and hoped this would resolve the serialization issues (even thou i do serialize joda LocalDateTime in other classes) but instead i've got this : 
com.novus.salat.util.ToObjectGlitch: 

  argument type mismatch

  $anon$2(class api.dto.MeterReadingsRequest @ repositories.when_necessary$$anon$1@58f59add) toObject failed on:
  SYM: api.dto.MeterReadingsRequest
  CONSTRUCTOR
public api.dto.MeterReadingsRequest(long,salesforce.package$MeterReadingSubmission)

---------- CONSTRUCTOR EXPECTS FOR PARAM [0] --------------
NAME:         reference
TYPE:      long
DEFAULT ARG   [Missing, but unnecessary because input value was supplied]
@Ignore      false
---------- CONSTRUCTOR INPUT ------------------------
TYPE: java.lang.Long
VALUE:
34567
------------------------------------------------------------
    

---------- CONSTRUCTOR EXPECTS FOR PARAM [1] --------------
NAME:         readings
TYPE:      salesforce.package$MeterReadingSubmission
DEFAULT ARG   [Missing, but unnecessary because input value was supplied]
@Ignore      false
---------- CONSTRUCTOR INPUT ------------------------
TYPE: com.mongodb.BasicDBList
VALUE:
[ "0012400000Dz7RM" , "0012400000Dz7RM" , "Some comment" , "CustomerReading" , "Localdate" , [ [ "20...
------------------------------------------------------------
Has anyone ever seen this?

P.S using "org.mongodb" %% "casbah" % "2.8.2"   and "com.novus" %% "salat" % "1.9.8"

Reply all
Reply to author
Forward
0 new messages