All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sbtmarathon.TypeMapDeserializer.scala Maven / Gradle / Ivy

The newest version!
package sbtmarathon

import org.json4sbt._
import org.json4sbt.jackson.JsonMethods._

case class TypeMap(underlying: Map[String, Manifest[_]])

object TypeMapDeserializer extends Serializer[TypeMap] {

  private val TypeMapClass = classOf[TypeMap]

  def serialize(implicit formats: Formats): PartialFunction[Any, JValue] = {
    throw new UnsupportedOperationException
  }

  def deserialize(implicit format: Formats): PartialFunction[(TypeInfo, JValue), TypeMap] = {
    case (TypeInfo(TypeMapClass, _), json) => json match {
      case JObject(jfields) => TypeMap(
        jfields.map {
          case (name, JObject(JField("manifest", jvalue) :: _)) => name -> ManifestSerialization.parse(jvalue)
          case _ => throw new MappingException(s"Can not convert JSON to TypeMap: `manifest` field expected")
        }.toMap
      )
      case _ => throw new MappingException(s"Can not convert JSON to TypeMap: top-level JSON object expected")
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy