0

Int とメッセージのリストを含む Inbox という名前のクラスがありますが、Messages は別のクラスであるため、問題は Inbox クラスを MongoDB に保存することであり、それをシリアル化する必要があるため、lift json を使用しています。逆シリアル化について

net.liftweb.json.MappingException: unknown error

ここに私のコードがあります

@SerialVersionUID(1)
class Inbox(val uuid : Int, var messageList : ListBuffer[Message] ) extends Serializable {

  /*
   * Auxiliary Constructor
   */
  def this(){
    this(0,  ListBuffer[Message]())
  }
 def addToMessageList(addMessage : Message)= {
   messageList += addMessage

 }
 var IdList = new MutableList[Int]()
    addUuidToList(uuid)

def addUuidToList(uuid : Int)  = {
    IdList += uuid   
  }


 /*
  * Getters
  */

// uuid

  def getUuid : Int ={
    uuid
  } 

/*
 * Returns sorted List based on dateTime attribute of the Message Class
 */

  def getMessageList : ListBuffer[Message] = {
   //var sortedList = messageList.sorted
    messageList
  }
  def getUuidsList:MutableList[Int]  = {
    IdList
  }
 }

Meesageクラスは

@SerialVersionUID(1)
class Message(val uuid: Int ,val subject : String, val body : String, var artworkUuid : Int,
    val dateTime : LocalDateTime = LocalDateTime.now()) extends Ordered[Message] with Serializable{
}



 Object Test extends App
    {
var messageList = new ListBuffer[Message]()

      val message2=new Message(123,"subject","bodyText",100,LocalDateTime.now(),UNREAD)
      val message3=new Message(321,"subject1","bodyText1",101,LocalDateTime.now(),READ)

 messageList+=message2
       messageList+=message3
        val inbox= new Inbox(333,messageList)

     val json =
                        ("inbox" ->
                        ("uuid" -> inbox.uuid)~ 
                        ("messageList" ->
                        inbox.getMessageList.map { msg =>
                        ("uuid" -> msg.uuid) ~
                        ("subject" -> msg.subject) ~
                        ("body" -> msg.body) ~
                        ("artworkUuid" -> msg.artworkUuid) ~
                        ("dateTime" -> msg.dateTime.toString()) ~
                        ("readStatusInt" -> msg.readStatusInt) ~
                        ("delete" ->
                        ("deleteStatusInt" -> msg.delete.deleteStatusInt) ~
                        ("deleteReasonInt" -> msg.delete.deleteReasonInt))
                        })
                        )

                       println(pretty(render(json)))

    }
     val inboxObj =json.extract[Inbox]
}

次の出力がコンソールに出力されます

{
  "inbox":{
    "uuid":333,
    "messageList":[{
      "uuid":123,
      "subject":"subject",
      "body":"bodyText",
      "artworkUuid":100,
      "dateTime":"2015-07-14T17:28:24.436",
      "readStatusInt":1,
      "delete":{
        "deleteStatusInt":0,
        "deleteReasonInt":0
      }
    },{
      "uuid":321,
      "subject":"subject1",
      "body":"bodyText1",
      "artworkUuid":101,
      "dateTime":"2015-07-14T17:28:24.493",
      "readStatusInt":0,
      "delete":{
        "deleteStatusInt":1,
        "deleteReasonInt":1
      }
    }]
  }
}
[error] (run-main-0) net.liftweb.json.MappingException: unknown error
net.liftweb.json.MappingException: unknown error
    at net.liftweb.json.Extraction$.extract(Extraction.scala:46)
    at net.liftweb.json.JsonAST$JValue.extract(JsonAST.scala:312)
    at TestActor$.delayedEndpoint$TestActor$1(TestActor.scala:369)
    at TestActor$delayedInit$body.apply(TestActor.scala:54)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App$$anonfun$main$1.apply(App.scala:76)
    at scala.App$$anonfun$main$1.apply(App.scala:76)
    at scala.collection.immutable.List.foreach(List.scala:383)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
    at scala.App$class.main(App.scala:76)
    at TestActor$.main(TestActor.scala:54)
    at TestActor.main(TestActor.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 49938
    at com.thoughtworks.paranamer.BytecodeReadingParanamer$ClassReader.<init>(BytecodeReadingParanamer.java:451)
    at com.thoughtworks.paranamer.BytecodeReadingParanamer$ClassReader.<init>(BytecodeReadingParanamer.java:431)
    at com.thoughtworks.paranamer.BytecodeReadingParanamer$ClassReader.<init>(BytecodeReadingParanamer.java:492)
    at com.thoughtworks.paranamer.BytecodeReadingParanamer$ClassReader.<init>(BytecodeReadingParanamer.java:337)
    at com.thoughtworks.paranamer.BytecodeReadingParanamer.lookupParameterNames(BytecodeReadingParanamer.java:100)
    at com.thoughtworks.paranamer.CachingParanamer.lookupParameterNames(CachingParanamer.java:75)
    at com.thoughtworks.paranamer.CachingParanamer.lookupParameterNames(CachingParanamer.java:68)
    at net.liftweb.json.Meta$ParanamerReader$.lookupParameterNames(Meta.scala:89)
    at net.liftweb.json.Meta$Reflection$.argsInfo$1(Meta.scala:237)
    at net.liftweb.json.Meta$Reflection$.constructorArgs(Meta.scala:253)
    at net.liftweb.json.Meta$Reflection$$anonfun$constructors$1.apply(Meta.scala:227)
    at net.liftweb.json.Meta$Reflection$$anonfun$constructors$1.apply(Meta.scala:227)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
    at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
    at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
    at scala.collection.mutable.ArrayOps$ofRef.map(ArrayOps.scala:186)
    at net.liftweb.json.Meta$Reflection$.constructors(Meta.scala:227)
    at net.liftweb.json.Meta$.net$liftweb$json$Meta$$constructors$1(Meta.scala:97)
    at net.liftweb.json.Meta$.mkConstructor$1(Meta.scala:124)
    at net.liftweb.json.Meta$.fieldMapping$1(Meta.scala:151)
    at net.liftweb.json.Meta$.net$liftweb$json$Meta$$toArg$1(Meta.scala:155)
    at net.liftweb.json.Meta$$anonfun$net$liftweb$json$Meta$$constructors$1$1$$anonfun$apply$1.apply(Meta.scala:99)
    at net.liftweb.json.Meta$$anonfun$net$liftweb$json$Meta$$constructors$1$1$$anonfun$apply$1.apply(Meta.scala:98)
    at scala.collection.immutable.List.map(List.scala:278)
    at net.liftweb.json.Meta$$anonfun$net$liftweb$json$Meta$$constructors$1$1.apply(Meta.scala:98)
    at net.liftweb.json.Meta$$anonfun$net$liftweb$json$Meta$$constructors$1$1.apply(Meta.scala:97)
    at scala.collection.immutable.List.map(List.scala:274)
    at net.liftweb.json.Meta$.net$liftweb$json$Meta$$constructors$1(Meta.scala:97)
    at net.liftweb.json.Meta$.mkConstructor$1(Meta.scala:124)
    at net.liftweb.json.Meta$.fieldMapping$1(Meta.scala:151)
    at net.liftweb.json.Meta$.mkContainer$1(Meta.scala:108)
    at net.liftweb.json.Meta$.fieldMapping$1(Meta.scala:139)
    at net.liftweb.json.Meta$.net$liftweb$json$Meta$$toArg$1(Meta.scala:155)
    at net.liftweb.json.Meta$$anonfun$net$liftweb$json$Meta$$constructors$1$1$$anonfun$apply$1.apply(Meta.scala:99)
    at net.liftweb.json.Meta$$anonfun$net$liftweb$json$Meta$$constructors$1$1$$anonfun$apply$1.apply(Meta.scala:98)
    at scala.collection.immutable.List.map(List.scala:278)
    at net.liftweb.json.Meta$$anonfun$net$liftweb$json$Meta$$constructors$1$1.apply(Meta.scala:98)
    at net.liftweb.json.Meta$$anonfun$net$liftweb$json$Meta$$constructors$1$1.apply(Meta.scala:97)
    at scala.collection.immutable.List.map(List.scala:274)
    at net.liftweb.json.Meta$.net$liftweb$json$Meta$$constructors$1(Meta.scala:97)
    at net.liftweb.json.Meta$$anonfun$mappingOf$1.apply(Meta.scala:169)
    at net.liftweb.json.Meta$$anonfun$mappingOf$1.apply(Meta.scala:161)
    at net.liftweb.json.Meta$Memo.memoize(Meta.scala:199)
    at net.liftweb.json.Meta$.mappingOf(Meta.scala:161)
    at net.liftweb.json.Extraction$.net$liftweb$json$Extraction$$mkMapping$1(Extraction.scala:194)
    at net.liftweb.json.Extraction$.net$liftweb$json$Extraction$$extract0(Extraction.scala:199)
    at net.liftweb.json.Extraction$.extract(Extraction.scala:43)
    at net.liftweb.json.JsonAST$JValue.extract(JsonAST.scala:312)
    at TestActor$.delayedEndpoint$TestActor$1(TestActor.scala:369)
    at TestActor$delayedInit$body.apply(TestActor.scala:54)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App$$anonfun$main$1.apply(App.scala:76)
    at scala.App$$anonfun$main$1.apply(App.scala:76)
    at scala.collection.immutable.List.foreach(List.scala:383)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
    at scala.App$class.main(App.scala:76)
    at TestActor$.main(TestActor.scala:54)
    at TestActor.main(TestActor.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
[trace] Stack trace suppressed: run last compile:run for the full output.

この問題を解決する方法を教えてください

4

1 に答える 1

0
net.liftweb.json.MappingException: unknown error

対応するscalaバージョンの不一致が原因です。依存関係がscalalift-jsonインストールと一致しない可能性があります。

乾杯 !!

于 2018-01-17T06:03:17.817 に答える