Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object Json {
- val mapper = new ObjectMapper() with ScalaObjectMapper
- mapper.enable(SerializationFeature.INDENT_OUTPUT)
- mapper.registerModule(DefaultScalaModule)
- implicit class JsonOps[T](obj : T) extends scala.AnyRef {
- def toJson: String = mapper.writeValueAsString(obj)
- }
- }
- case class Person(name: String, age: Int)
- object Example {
- import Json._
- def run = {
- val x = Person("Frol", 123).toJson
- println(x) // outputs {"name":"Frol","age":123}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement