Error with asDBObject

203 views
Skip to first unread message

Pablo Mincz

unread,
Sep 2, 2014, 4:33:08 PM9/2/14
to scala...@googlegroups.com
Hi,

I'm trying to convert a case class to a DBObject because I want to save it in Mongo.

val mongoElement = grater[AccessTokenDB].asDBObject(element)

The case class is:

case class AccessTokenDB(accessToken: String, userId: Long, refreshToken: Option[String], expiresIn: Int, createdAt: java.sql.Timestamp, requests: Int = 0)

And I put in the object that do the insert the following registers:

RegisterConversionHelpers()
RegisterJodaTimeConversionHelpers()
RegisterJodaLocalDateTimeConversionHelpers()

But I get the error:

Caused by: com.novus.salat.util.MissingPickledSig: FAIL: class 'class com.viajeros.oauth.dao.OAuthJsonProtocol$AccessTokenDB' is missing both @ScalaSig and .class file!
at com.novus.salat.ClassAnalyzer$.findSym(ClassAnalyzer.scala:59) ~[salat-util_2.10-1.9.9.jar:1.9.9]
at com.novus.salat.ClassAnalyzer.<init>(ClassAnalyzer.scala:136) ~[salat-util_2.10-1.9.9.jar:1.9.9]
at com.novus.salat.ConcreteGrater.ca$lzycompute(Grater.scala:118) ~[salat-core_2.10-1.9.9.jar:1.9.9]
at com.novus.salat.ConcreteGrater.ca(Grater.scala:118) ~[salat-core_2.10-1.9.9.jar:1.9.9]
at com.novus.salat.ConcreteGrater.useTypeHint$lzycompute(Grater.scala:122) ~[salat-core_2.10-1.9.9.jar:1.9.9]
at com.novus.salat.ConcreteGrater.useTypeHint(Grater.scala:120) ~[salat-core_2.10-1.9.9.jar:1.9.9]
at com.novus.salat.ConcreteGrater.asDBObject(Grater.scala:282) ~[salat-core_2.10-1.9.9.jar:1.9.9]
at com.viajeros.oauth.mongo.util.AccessTokenMongoClient$.insert(AccessTokenMongoClient.scala:23) ~[classes/:na]
at com.viajeros.oauth.service.UserDataHandler.createAccessToken(UserDataHandler.scala:61) ~[classes/:na]
at com.viajeros.oauth.provider.GrantHandler$$anonfun$issueAccessToken$1.apply(GrantHandler.scala:32) ~[classes/:na]
at com.viajeros.oauth.provider.GrantHandler$$anonfun$issueAccessToken$1.apply(GrantHandler.scala:26) ~[classes/:na]
at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:251) ~[scala-library-2.10.4.jar:na]
...

Someone know how to fix this?

Thanks!

rose katherine toomey

unread,
Sep 2, 2014, 5:09:33 PM9/2/14
to scala-salat
Hi Paul,

Make sure that you have defined this class inside a package.  (Also, Salat can't serialize classes defined in the console or REPL.)

If that doesn't fix your problem, please make a Github project that demonstrates your issue, and I will fork it and fix it.

Best,
Rose


--
You received this message because you are subscribed to the Google Groups "scala-salat" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-salat...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pablo Mincz

unread,
Sep 3, 2014, 11:30:32 AM9/3/14
to scala...@googlegroups.com
Thanks a lot Rose!

I did not define the case class inside a package.

I have another problem and I think you can help me.

I have the case class:

case class AccessTokenMongo(accessToken: String, userId: Long, refreshToken: Option[String], expiresIn: Int, createdAt: java.sql.Timestamp, requests: Int = 0)

And I can save it mongoDB perfectly, but when I did this to retrieve it:

response.map { element =>
      Some(grater[AccessTokenMongo].asObject(element))
    }.getOrElse(None)

I get this error:

com.novus.salat.util.ToObjectGlitch: 

  argument type mismatch

  $anon$2(class com.viajeros.oauth.dao.AccessTokenMongo @ com.novus.salat.global.package$$anon$1@1d35d64) toObject failed on:
  SYM: com.viajeros.oauth.dao.AccessTokenMongo
  CONSTRUCTOR
public com.viajeros.oauth.dao.AccessTokenMongo(java.lang.String,long,scala.Option<java.lang.String>,int,java.sql.Timestamp,int)

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

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

---------- CONSTRUCTOR EXPECTS FOR PARAM [2] --------------
NAME:         refreshToken
TYPE:      scala.Option<java.lang.String>
DEFAULT ARG   [Missing, but unnecessary because input value was supplied]
@Ignore      false
---------- CONSTRUCTOR INPUT ------------------------
TYPE: scala.Some[A]
VALUE:
Some(YTg3NThmZjMtMzkzMS00YmZhLThhOWQtMjAwMDQyMWZlODE4)
------------------------------------------------------------
    

---------- CONSTRUCTOR EXPECTS FOR PARAM [3] --------------
NAME:         expiresIn
TYPE:      int
DEFAULT ARG   [Missing, but unnecessary because input value was supplied]
@Ignore      false
---------- CONSTRUCTOR INPUT ------------------------
TYPE: java.lang.Integer
VALUE:
3600
------------------------------------------------------------
    

---------- CONSTRUCTOR EXPECTS FOR PARAM [4] --------------
NAME:         createdAt
TYPE:      java.sql.Timestamp
DEFAULT ARG   [Missing, but unnecessary because input value was supplied]
@Ignore      false
---------- CONSTRUCTOR INPUT ------------------------
TYPE: org.joda.time.LocalDateTime
VALUE:
2014-09-03T12:25:43.807
------------------------------------------------------------
    

---------- CONSTRUCTOR EXPECTS FOR PARAM [5] --------------
NAME:         requests
TYPE:      int
DEFAULT ARG   0
@Ignore      false
---------- CONSTRUCTOR INPUT ------------------------
TYPE: java.lang.Integer
VALUE:
0
------------------------------------------------------------
    

  
at com.novus.salat.ConcreteGrater.feedArgsToConstructor(Grater.scala:340) ~[salat-core_2.10-1.9.9.jar:1.9.9]
at com.novus.salat.ConcreteGrater.asObject(Grater.scala:317) ~[salat-core_2.10-1.9.9.jar:1.9.9]


I think maybe is for the _id that is not in my case class.

Is mandatory to have an id in the case class?

Thanks a lot again!

Regards,
Paul.

rose katherine toomey

unread,
Sep 3, 2014, 11:48:14 AM9/3/14
to scala-salat
Hi Pablo,

java.sql.Timestamp is not supported - use java.util.Date (java.sql.Timestamp is just a thin wrapper around java.util.Date anyway) or a Joda DateTime.  

On a side note, are you aware SalatDAO will save you a lot of trouble?  You really don't have to write this kind of manual serialization and deserialization code.

Best,
Rose



Reply all
Reply to author
Forward
0 new messages