-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #945 from ramazanyich/jsobject_serializable
make ImmutableLinkedHashMap serializable
- Loading branch information
Showing
4 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
play-json/jvm/src/test/scala/play/api/libs/json/JsObjectSerializationSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package play.api.libs.json | ||
|
||
import org.specs2.mutable._ | ||
import play.api.libs.json.Json._ | ||
|
||
import java.io.{ ByteArrayInputStream, ByteArrayOutputStream, ObjectInputStream, ObjectOutputStream } | ||
|
||
class JsObjectSerializationSpec extends Specification { | ||
"JsObject" should { | ||
"serialize/deserialize correctly" in { | ||
val originalObj = Json.obj( | ||
"field1" -> 123, | ||
"field2" -> "abc", | ||
"field3" -> JsNull, | ||
"obj" -> Json.obj("field1" -> 234), | ||
"arr" -> JsArray( | ||
Seq( | ||
JsString("abc"), | ||
JsNumber(123), | ||
JsBoolean(true), | ||
JsNull, | ||
Json.obj("field1" -> 345) | ||
) | ||
) | ||
) | ||
|
||
val bos = new ByteArrayOutputStream() | ||
val out = new ObjectOutputStream(bos) | ||
out.writeObject(originalObj) | ||
|
||
val bis = new ByteArrayInputStream(bos.toByteArray) | ||
val in = new ObjectInputStream(bis) | ||
in.readObject().asInstanceOf[JsObject].must(beEqualTo(originalObj)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters