Skip to content

Commit

Permalink
Merge pull request #67 from xuwei-k/patch-2
Browse files Browse the repository at this point in the history
use `scala.reflect.ClassTag` instead of deprecated `Manifest`
  • Loading branch information
unkarjedy authored Nov 4, 2024
2 parents 66701d4 + f6c9c75 commit 01616c0
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jetbrains.sbt
package structure

import scala.reflect.ClassTag
import scala.xml._

/**
Expand All @@ -22,12 +23,12 @@ object XmlSerializer {
def deserialize[T](implicit serializer: XmlSerializer[T]): Seq[T] =
nodeSeq.flatMap(_.deserialize[T].fold(_ => None, x => Some(x)))

def deserializeOne[T](implicit serializer: XmlSerializer[T], manifest: Manifest[T]): Either[Throwable,T] = {
def deserializeOne[T](implicit serializer: XmlSerializer[T], manifest: ClassTag[T]): Either[Throwable,T] = {
val ts = nodeSeq.map(_.deserialize[T]).collect { case Right(t) => t }
if (ts.isEmpty)
Left(new Error("None of " + manifest.erasure.getSimpleName + " is found in " + nodeSeq))
Left(new Error("None of " + manifest.runtimeClass.getSimpleName + " is found in " + nodeSeq))
else if (ts.length > 1)
Left(new Error("Multiple instances of " + manifest.erasure.getSimpleName + " are found in " + nodeSeq))
Left(new Error("Multiple instances of " + manifest.runtimeClass.getSimpleName + " are found in " + nodeSeq))
else
Right(ts.head)
}
Expand Down

0 comments on commit 01616c0

Please sign in to comment.