0

Reasonably new to scala, I'm looking for a way to serialize and deserialize a class to/from JSON. I'm familiar with Jackson annotations from Java, and would like to use that style if it makes sense in scala.

Two parts that are causing me problems: private constructor parameters, and HashSets.

I've tried json4s and jackson-module-scala, but seem to be able to get them to do what I want. Both reported errors with HashSets. Sorry, don't have the errors handy, can find if necessary.

As a test, here's a class I'm trying to serialize then deserialize:

class foo(val public: String, private: String) {
    someList: mutable.HashMap[String] = new mutable.HashMap[String]("bar")

    def func = { .. }
}

Thanks for any help!

mozboz
  • 1,070
  • 12
  • 24
  • First off, Scala is not Java. While you can use annotations, there are better ways. Jackson-module-scala is effective and documented well enough, but I recommend looking at Scala [pickling](https://github.com/scala/pickling) because it is elegant, fast and handles type effectively. [This answer](http://stackoverflow.com/questions/23072118/scala-pickling-how/23980981#23980981) may also help. – David Weber Jul 01 '14 at 19:29

1 Answers1

1

Did you try using case classes? Otherwise i think there is an annotation to make the class compatible with Pojo classes @beanproperty. You can find more here https://twitter.github.io/scala_school/java.html

Fabio Fumarola
  • 430
  • 3
  • 9
  • 1
    No - I've seen case classes used as examples for the scala JSON tools, but don't understand why or how to use them for my case. – mozboz Jun 30 '14 at 11:40