mozboz
mozboz

Reputation: 1119

(de)serialize class to/from JSON

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!

Upvotes: 0

Views: 219

Answers (1)

Fabio Fumarola
Fabio Fumarola

Reputation: 508

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

Upvotes: 1

Related Questions