diff options
author | Magnolia K <magnolia.k@icloud.com> | 2017-01-22 16:57:59 +0900 |
---|---|---|
committer | Magnolia K <magnolia.k@icloud.com> | 2017-01-22 16:57:59 +0900 |
commit | 3054019aae26ec46f26239b3938af5e16f63111f (patch) | |
tree | 73fe7be6eb8e7328a722e4f1027e82428152a799 /src/main | |
parent | 537cb5bca7eb73750fc2e86e4a2ea6605714482b (diff) | |
download | spray-json-3054019aae26ec46f26239b3938af5e16f63111f.tar.gz spray-json-3054019aae26ec46f26239b3938af5e16f63111f.tar.bz2 spray-json-3054019aae26ec46f26239b3938af5e16f63111f.zip |
Replace ClassManifest to ClassTag
ClassManifest has been deprecated as of 2.10 and replaced with ClassTag
because a warning message is displayed at compile time.
Diffstat (limited to 'src/main')
3 files changed, 12 insertions, 6 deletions
diff --git a/src/main/boilerplate/spray/json/ProductFormatsInstances.scala.template b/src/main/boilerplate/spray/json/ProductFormatsInstances.scala.template index 3d29b58..03d9492 100644 --- a/src/main/boilerplate/spray/json/ProductFormatsInstances.scala.template +++ b/src/main/boilerplate/spray/json/ProductFormatsInstances.scala.template @@ -16,11 +16,14 @@ package spray.json +import scala.reflect.ClassTag + trait ProductFormatsInstances { self: ProductFormats with StandardFormats => [# // Case classes with 1 parameters - def jsonFormat1[[#P1 :JF#], T <: Product :ClassManifest](construct: ([#P1#]) => T): RootJsonFormat[T] = { - val Array([#p1#]) = extractFieldNames(classManifest[T]) + def jsonFormat1[[#P1 :JF#], T <: Product :ClassTag](construct: ([#P1#]) => T): RootJsonFormat[T] = { + val c = implicitly[ClassTag[T]] + val Array([#p1#]) = extractFieldNames(c) jsonFormat(construct, [#p1#]) } def jsonFormat[[#P1 :JF#], T <: Product](construct: ([#P1#]) => T, [#fieldName1: String#]): RootJsonFormat[T] = new RootJsonFormat[T]{ diff --git a/src/main/scala/spray/json/CollectionFormats.scala b/src/main/scala/spray/json/CollectionFormats.scala index 24ab1dd..9a3e8fd 100644 --- a/src/main/scala/spray/json/CollectionFormats.scala +++ b/src/main/scala/spray/json/CollectionFormats.scala @@ -17,6 +17,8 @@ package spray.json +import scala.reflect.ClassTag + trait CollectionFormats { /** @@ -33,7 +35,7 @@ trait CollectionFormats { /** * Supplies the JsonFormat for Arrays. */ - implicit def arrayFormat[T :JsonFormat :ClassManifest] = new RootJsonFormat[Array[T]] { + implicit def arrayFormat[T :JsonFormat :ClassTag] = new RootJsonFormat[Array[T]] { def write(array: Array[T]) = JsArray(array.map(_.toJson).toVector) def read(value: JsValue) = value match { case JsArray(elements) => elements.map(_.convertTo[T]).toArray[T] @@ -90,4 +92,4 @@ trait CollectionFormats { case x => deserializationError("Expected Collection as JsArray, but got " + x) } } -}
\ No newline at end of file +} diff --git a/src/main/scala/spray/json/ProductFormats.scala b/src/main/scala/spray/json/ProductFormats.scala index 7d6c63e..81a48af 100644 --- a/src/main/scala/spray/json/ProductFormats.scala +++ b/src/main/scala/spray/json/ProductFormats.scala @@ -19,6 +19,7 @@ package spray.json import java.lang.reflect.Modifier import scala.annotation.tailrec import scala.util.control.NonFatal +import scala.reflect.ClassTag /** * Provides the helpers for constructing custom JsonFormat implementations for types implementing the Product trait @@ -64,8 +65,8 @@ trait ProductFormats extends ProductFormatsInstances { case _ => deserializationError("Object expected in field '" + fieldName + "'", fieldNames = fieldName :: Nil) } - protected def extractFieldNames(classManifest: ClassManifest[_]): Array[String] = { - val clazz = classManifest.erasure + protected def extractFieldNames(tag: ClassTag[_]): Array[String] = { + val clazz = tag.runtimeClass try { // copy methods have the form copy$default$N(), we need to sort them in order, but must account for the fact // that lexical sorting of ...8(), ...9(), ...10() is not correct, so we extract N and sort by N.toInt |