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

tethys.writers.instances.MapWriters.scala Maven / Gradle / Ivy

There is a newer version: 0.29.0
Show newest version
package tethys.writers.instances

import tethys.{JsonObjectWriter, JsonWriter, specializations}
import tethys.writers.KeyWriter
import tethys.writers.tokens.TokenWriter

private[tethys] trait MapWriters extends IterableWriters {
  implicit def mapWriter[K, A](implicit
      keyWriter: KeyWriter[K],
      valueWriter: JsonWriter[A]
  ): JsonObjectWriter[Map[K, A]] = new JsonObjectWriter[Map[K, A]] {
    override def writeValues(
        value: Map[K, A],
        tokenWriter: TokenWriter
    ): Unit = {
      val valueIterator = value.iterator
      while (valueIterator.hasNext) {
        val v = valueIterator.next()
        tokenWriter.writeFieldName(keyWriter.toKey(v._1))
        valueWriter.write(v._2, tokenWriter)
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy