Skip to content

Instantly share code, notes, and snippets.

@lab3
Created March 6, 2015 17:30
Show Gist options
  • Save lab3/a0045a92f551fa3fe7a6 to your computer and use it in GitHub Desktop.
Save lab3/a0045a92f551fa3fe7a6 to your computer and use it in GitHub Desktop.
json4s generic
package com.len.Boot
import org.json4s._
import org.json4s.native.Serialization
import org.json4s.native.Serialization.{read, write}
object Boot {
implicit val formats = DefaultFormats + FieldSerializer[item[String]]()
def main(args: Array[String]): Unit ={
val tmp = new item[String]("g").asInstanceOf[myGeneric[String]]
println(write(tmp))
}
class item[T](value: T) extends myGeneric[T]{
var genericField: T = value
var otherField = "other"
var customField = "custom"
}
trait myGeneric[T]{
var genericField: T
var otherField: String
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment