forked from json4s/json4s
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add org.json4s.Compat. avoid reflection
- Loading branch information
Showing
3 changed files
with
30 additions
and
46 deletions.
There are no files selected for viewing
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,15 @@ | ||
package org.json4s | ||
|
||
import scala.language.reflectiveCalls | ||
|
||
private[json4s] object Compat { | ||
def makeCollection(clazz: Class[_], array: Array[_]): Option[Any] = { | ||
reflect.ScalaSigReader.companions(clazz.getName).flatMap(_._2).map { c => | ||
val builder = c | ||
.asInstanceOf[ {def newBuilder: collection.mutable.Builder[Any, Any]}] | ||
.newBuilder | ||
builder ++= array | ||
builder.result | ||
} | ||
} | ||
} |
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,11 @@ | ||
package org.json4s | ||
|
||
import scala.language.reflectiveCalls | ||
|
||
private[json4s] object Compat { | ||
def makeCollection(clazz: Class[_], array: Array[_]): Option[Any] = { | ||
reflect.ScalaSigReader.companions(clazz.getName).flatMap(_._2).map { | ||
_.asInstanceOf[ {def apply(elems: collection.Seq[_]): Any}].apply(array.toSeq) | ||
} | ||
} | ||
} |
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