score:0

Accepted answer

Finally, I have resolved the error by changing how the JSON value is created. Instead of using the json4s wrapper:

org.json4s.jackson.Serialization.write()

I switched to using Jackson mapper directly:

com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString()

Edit: In my ScalatraBootstrap.init() method, I have defined the Jackson's ObjectMapper:

import com.fasterxml.jackson.databind.ObjectMapper

class ScalatraBootstrap extends LifeCycle {

    override def init(context: ServletContext) {

        implicit val objectMapper = new ObjectMapper

        //omitting the rest of the code...
    }
    ...
}

And here is my service class where I'm fetching the net.example.MyClass and transforming it to JSON with the ObjectMapper:

import net.example.MyClass
import com.fasterxml.jackson.databind.ObjectMapper

class MyService(val objectMapper: ObjectMapper) {

    def getMyClassAsJson() {
        val result: MyClass = // calling a service which provides the MyClass object
        return objectMapper.writeValueAsString(result)
    }
}

score:0

you post the json including net.example.MyClass[]. As MyClass[] is a array, the ScalaSig cannot resolved object array, so you should use ArrayList<net.example.MyClass>.


Related Query

More Query from same tag