File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
enumeratum-play-json/src/test/scala/enumeratum Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ package enumeratum
44 * Created by Lloyd on 2/4/15.
55 */
66sealed trait Dummy
7- object Dummy extends Enum [Dummy ] {
7+ object Dummy extends Enum [Dummy ] with PlayJsonEnum [ Dummy ] {
88 case object A extends Dummy
99 case object B extends Dummy
1010 case object C extends Dummy
Original file line number Diff line number Diff line change 1+ package enumeratum
2+
3+ import org .scalatest .{ Matchers , FunSpec }
4+ import play .api .libs .json .{ JsNumber , JsString , Json => PlayJson }
5+ import org .scalatest .OptionValues ._
6+
7+ class PlayJsonEnumSpec extends FunSpec with Matchers {
8+
9+ describe(" JSON serdes" ) {
10+
11+ describe(" deserialisation" ) {
12+
13+ it(" should work with valid values" ) {
14+ JsString (" A" ).asOpt[Dummy ].value shouldBe Dummy .A
15+ }
16+
17+ it(" should fail with invalid values" ) {
18+ JsString (" D" ).asOpt[Dummy ] shouldBe None
19+ JsNumber (2 ).asOpt[Dummy ] shouldBe None
20+ }
21+ }
22+
23+ describe(" serialisation" ) {
24+
25+ it(" should serialise values to JsString" ) {
26+ PlayJson .toJson(Dummy .A ) shouldBe (JsString (" A" ))
27+ }
28+
29+ }
30+
31+ }
32+
33+ }
You can’t perform that action at this time.
0 commit comments