3

I have looked at https://github.com/debasishg/sjson and using EGit I was not able to import this code for Scala 2.8.1.

Ideally, this seems to be the best library that should work, but when I loaded master it is currently empty.

I am trying to use Jersey (http://jersey.java.net) to build a REST service in Scala, but the JSON serialization is where I am stuck, as I would prefer to use something written in Scala.

Unfortunately there isn't anything for Scala at http://json.org/.

So, how do I import SJSON for use in Scala 2.8.1, for Eclipse, or, is there a more updated library that would work as well?

James Black
  • 41,583
  • 10
  • 86
  • 166

3 Answers3

3

Lift JSON has prebuilt 2.8.1 compatible versions at:

http://scala-tools.org/repo-releases/net/liftweb/lift-json_2.8.1/

Please see "Installation" from:

https://github.com/lift/lift/tree/master/framework/lift-base/lift-json

Joni
  • 2,779
  • 23
  • 17
2

Writing REST services with Jersey (in Java) is what I do every day at work. I use the integration Jersey has with Jackson for JSON serialization and deserialization. Using another library with Jersey would be swimming upstream. You're using a REST library written in Java, so why not a JSON library in Java too, especially since it just works out of the box?

When I want to write a Scala REST service, I use SBT, the Scalatra web framework and lift-json. It works great.

I don't use Eclipse, but the selection of JSON library is orthogonal to what IDE/editor/etc you use. I would certainly never want to choose a library based on its ability to play nice in Eclipse.

If you're interested in using Scala to write a REST service (very quickly), start with this tutorial: http://blog.everythings-beta.com/?p=430

Add some case classes and lift-json support for parsing them. Excellent examples here: https://github.com/lift/lift/tree/master/framework/lift-base/lift-json/ (scroll down) You can add lift-json to your SBT project with:

val lift_json = "net.liftweb" %% "lift-json" % "2.1"

I've found lift-json excellent for both parsing and generating JSON. But if I'm using Jersey, I use the built in support for Jackson, since it is excellent and there's no reason to use anything else.

Janx
  • 3,285
  • 3
  • 19
  • 24
  • My only problem with using lift is that it is much larger than what I need, as this will only be a REST service, I am not going to be serving any pages, doing anything dynamic, just reacting to calls. – James Black Jan 03 '11 at 02:42
  • 1
    Yep - I agree 100%. Lift is great for what it does when you need it. That's why is suggest Scalatra - it's incredibly lightweight. Makes Jersey look like Lift. And you can use lift-json (the library) independent of Lift the framework using the dependency I posted. It's a pretty brilliant lightweight REST-service-in-5-minutes kind of setup. EDIT - definitely check this out: http://blog.everythings-beta.com/?p=430 - Scalatra/SBT/MongoDB is my goto quick REST service platform now. – Janx Jan 03 '11 at 03:10
  • Thank you for the links. I will check them out now. This is my first time trying to use REST with Scala, in case you didn't notice. :) – James Black Jan 03 '11 at 03:28
1

If you look at the fork graph of that repo, you will see ginkel's version of sjson with:

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you. I thought it was empty because I looked in the wrong directory, but I think the other fork may be a better choice. – James Black Jan 02 '11 at 16:39