Skip to content

Nodeseq serialization #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions jvm/src/test/scala/scala/xml/SerializationTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package scala.xml

import java.io._

import org.junit.Assert.assertEquals
import org.junit.Test

class SerializationTest {
def roundTrip[T](obj: T): T = {
def serialize(in: T): Array[Byte] = {
val bos = new ByteArrayOutputStream()
val oos = new ObjectOutputStream(bos)
oos.writeObject(in)
oos.flush()
bos.toByteArray()
}

def deserialize(in: Array[Byte]): T = {
val bis = new ByteArrayInputStream(in)
val ois = new ObjectInputStream(bis)
ois.readObject.asInstanceOf[T]
}

deserialize(serialize(obj))
}

@Test
def xmlLiteral: Unit = {
val n = <node/>
assertEquals(n, roundTrip(n))
}

@Test
def empty: Unit = {
assertEquals(NodeSeq.Empty, roundTrip(NodeSeq.Empty))
}

@Test
def implicitConversion: Unit = {
val parent = <parent><child></child><child/></parent>
val children: Seq[Node] = parent.child
val asNodeSeq: NodeSeq = children
assertEquals(asNodeSeq, roundTrip(asNodeSeq))
}
}
2 changes: 1 addition & 1 deletion shared/src/main/scala/scala/xml/NodeSeq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ object NodeSeq {
* @author Burak Emir
* @version 1.0
*/
abstract class NodeSeq extends AbstractSeq[Node] with immutable.Seq[Node] with SeqLike[Node, NodeSeq] with Equality {
abstract class NodeSeq extends AbstractSeq[Node] with immutable.Seq[Node] with SeqLike[Node, NodeSeq] with Equality with Serializable {

/** Creates a list buffer as builder for this class */
override protected[this] def newBuilder = NodeSeq.newBuilder
Expand Down