diff options
author | Johannes Rudolph <johannes.rudolph@gmail.com> | 2018-07-26 15:14:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-26 15:14:09 +0200 |
commit | 245a3fbeb96c6e6df711daf9989350d2d7f9ab81 (patch) | |
tree | 196cf8a84460ad66c06f244b4ae4d798633a76ab /src | |
parent | 326a001a44bd818750f2baa3f65e68184f5a2d5a (diff) | |
parent | a26f45ba61e39c7eb3c890a07ebb96edb7dbf987 (diff) | |
download | spray-json-245a3fbeb96c6e6df711daf9989350d2d7f9ab81.tar.gz spray-json-245a3fbeb96c6e6df711daf9989350d2d7f9ab81.tar.bz2 spray-json-245a3fbeb96c6e6df711daf9989350d2d7f9ab81.zip |
Merge pull request #219 from magnolia-k/fix_warnings_about_manifest
Replace ClassManifest with ClassTag
Diffstat (limited to 'src')
3 files changed, 11 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..401ac83 100644 --- a/src/main/boilerplate/spray/json/ProductFormatsInstances.scala.template +++ b/src/main/boilerplate/spray/json/ProductFormatsInstances.scala.template @@ -16,11 +16,13 @@ package spray.json +import scala.reflect.{ classTag, 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 Array([#p1#]) = extractFieldNames(classTag[T]) 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 |