Skip to content

Commit

Permalink
Respect Config#tagName in merge methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdziuban committed Aug 13, 2024
1 parent ec02af6 commit 19fc8de
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ object upickle extends Module{
* Auto-generated picklers and unpicklers, used for creating the 22
* versions of tuple-picklers and case-class picklers
*/
trait Generated extends TupleReadWriters{
trait Generated extends TupleReadWriters { self: upickle.core.Config =>
${tuples.mkString("\n")}
}
""")
Expand Down
8 changes: 4 additions & 4 deletions upickle/core/src/upickle/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import scala.reflect.ClassTag
* other internal files can use it, while also mixing it into the `upickle`
* package to form the public API1
*/
trait Types{ types =>
trait Types { types: Config =>

/**
* A combined [[Reader]] and [[Writer]], along with some utility methods.
Expand Down Expand Up @@ -39,7 +39,7 @@ trait Types{ types =>
new TaggedReadWriter.Node(tagKey, rws.asInstanceOf[Seq[TaggedReadWriter[T]]]:_*)
}

def merge[T](rws: ReadWriter[_ <: T]*): TaggedReadWriter[T] = merge(Annotator.defaultTagKey, rws:_*)
def merge[T](rws: ReadWriter[_ <: T]*): TaggedReadWriter[T] = merge(tagName, rws:_*)

implicit def join[T](implicit r0: Reader[T], w0: Writer[T]): ReadWriter[T] = (r0, w0) match{
// Make sure we preserve the tagged-ness of the Readers/Writers being
Expand Down Expand Up @@ -119,7 +119,7 @@ trait Types{ types =>
new TaggedReader.Node(tagKey, readers0.asInstanceOf[Seq[TaggedReader[T]]]:_*)
}

def merge[T](readers0: Reader[_ <: T]*): TaggedReader.Node[T] = merge(Annotator.defaultTagKey, readers0:_*)
def merge[T](readers0: Reader[_ <: T]*): TaggedReader.Node[T] = merge(tagName, readers0:_*)
}

/**
Expand Down Expand Up @@ -164,7 +164,7 @@ trait Types{ types =>
}

trait TaggedReader[T] extends SimpleReader[T]{
private[upickle] def tagKey: String = Annotator.defaultTagKey
private[upickle] def tagKey: String = tagName

def findReader(s: String): Reader[T]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package upickle.implicits
import scala.language.experimental.macros
import scala.language.higherKinds
import scala.reflect.ClassTag
import upickle.core.{Abort, AbortException, ArrVisitor, NoOpVisitor, ObjVisitor, Visitor}
import upickle.core.{Abort, AbortException, ArrVisitor, Config, NoOpVisitor, ObjVisitor, Visitor}

/**
* Basic functionality to be able to read and write objects. Kept as a trait so
* other internal files can use it, while also mixing it into the `upickle`
* package to form the public API1
*/
trait CaseClassReadWriters extends upickle.core.Types{
trait CaseClassReadWriters extends upickle.core.Types { self: Config =>
abstract class CaseClassReader[V] extends SimpleReader[V] {
override def expectedMsg = "expected dictionary"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package upickle.implicits
import scala.language.experimental.macros
import scala.language.higherKinds
import scala.reflect.ClassTag
import upickle.core.{Visitor, Abort, ArrVisitor, ObjVisitor, NoOpVisitor}
import upickle.core.{Visitor, Abort, ArrVisitor, Config, ObjVisitor, NoOpVisitor}

/**
* Basic functionality to be able to read and write objects. Kept as a trait so
* other internal files can use it, while also mixing it into the `upickle`
* package to form the public API1
*/
trait TupleReadWriters extends upickle.core.Types{
trait TupleReadWriters extends upickle.core.Types { self: Config =>


class TupleNWriter[V](val writers: Array[Writer[_]], val f: V => Array[Any]) extends Writer[V]{
Expand Down
4 changes: 2 additions & 2 deletions upickle/implicits/src/upickle/implicits/Writers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package upickle.implicits

import java.util.UUID

import upickle.core.{ Visitor, Annotator }
import upickle.core.{ Config, Visitor, Annotator }

import scala.concurrent.duration.{Duration, FiniteDuration}
import scala.language.higherKinds
Expand Down Expand Up @@ -240,7 +240,7 @@ trait Writers extends upickle.core.Types
/**
* This needs to be split into a separate trait due to https://github.com/scala/bug/issues/11768
*/
trait LowPriWriters extends upickle.core.Types{
trait LowPriWriters extends upickle.core.Types { self: Config =>
implicit def SeqLikeWriter[C[_] <: Iterable[_], T](implicit r: Writer[T]): Writer[C[T]] = new Writer[C[T]] {
def write0[R](out: Visitor[_, R], v: C[T]): R = {
val ctx = out.visitArray(v.size, -1).narrow
Expand Down
2 changes: 1 addition & 1 deletion upickle/src-js/upickle/WebJson.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package upickle

import scala.scalajs.js

trait WebJson extends upickle.core.Types {
trait WebJson extends upickle.core.Types { self: upickle.core.Config =>
object web {
def read[T: Reader](s: String) = {
ujson.WebJson.transform(js.JSON.parse(s), implicitly[Reader[T]])
Expand Down
2 changes: 1 addition & 1 deletion upickle/src-jvm/upickle/WebJson.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package upickle


trait WebJson extends upickle.core.Types {
trait WebJson extends upickle.core.Types { self: upickle.core.Config =>

}
2 changes: 1 addition & 1 deletion upickle/src-native/upickle/WebJson.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package upickle

trait WebJson extends upickle.core.Types {
trait WebJson extends upickle.core.Types { self: upickle.core.Config =>

}

0 comments on commit 19fc8de

Please sign in to comment.