Skip to content

Instantly share code, notes, and snippets.

@drstevens
Forked from debasishg/gist:b2bb9e12f9de6f601d86
Last active August 29, 2015 14:18

Revisions

  1. @debasishg debasishg created this gist Apr 4, 2015.
    15 changes: 15 additions & 0 deletions gistfile1.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    trait Writes[T] {
    def writes(o: T): JsValue
    }

    trait Reads[T] {
    def reads(json: JsValue): T
    }

    trait Format[T] extends Writes[T] with Reads[T]

    object JsonSerialization {
    def tojson[T](o: T)(implicit tjs: Writes[T]): JsValue = tjs.writes(o)

    def fromjson[T](json: JsValue)(implicit fjs: Reads[T]): T = fjs.reads(json)
    }