@@ -31,7 +31,7 @@ trait GenCodec[T] {
31
31
def write (output : Output , value : T ): Unit
32
32
}
33
33
34
- object GenCodec extends FallbackMapCodecs with TupleGenCodecs {
34
+ object GenCodec extends RecursiveAutoCodecs with TupleGenCodecs {
35
35
/**
36
36
* Macro that automatically materializes a [[GenCodec ]] for some type `T`, which must be one of:
37
37
* <ul>
@@ -405,48 +405,6 @@ object GenCodec extends FallbackMapCodecs with TupleGenCodecs {
405
405
implicit lazy val NothingAutoCodec : GenCodec .Auto [Nothing ] = GenCodec .Auto [Nothing ](NothingCodec )
406
406
}
407
407
408
- /**
409
- * Contains readers for maps where there is no DBKeyCodec for key type. In such case, we assume reading from a list
410
- * of key-value pairs instead of JSON object.
411
- */
412
- trait FallbackMapCodecs extends RecursiveAutoCodecs { this : GenCodec .type =>
413
- private def readKVPair [K : GenCodec , V : GenCodec ](input : ObjectInput ): (K , V ) = {
414
- val key = read[K ](input.nextField().assertField(" k" ))
415
- val value = read[V ](input.nextField().assertField(" v" ))
416
- (key, value)
417
- }
418
-
419
- private def writeKVPair [K , V ](output : ObjectOutput , key : K , value : V )(implicit keyCodec : GenCodec [K ], valueCodec : GenCodec [V ]): Unit = {
420
- keyCodec.write(output.writeField(" k" ), key)
421
- valueCodec.write(output.writeField(" v" ), value)
422
- output.finish()
423
- }
424
-
425
- private def collectPairsTo [K : GenCodec , V : GenCodec , C ](li : ListInput )(implicit cbf : CanBuildFrom [Nothing , (K , V ), C ]): C = {
426
- val b = cbf()
427
- while (li.hasNext) {
428
- b += readKVPair[K , V ](li.nextElement().readObject())
429
- }
430
- b.result()
431
- }
432
-
433
- implicit def fallbackMapCodec [M [X , Y ] <: BMap [X , Y ], K : GenCodec , V : GenCodec ](
434
- implicit cbf : CanBuildFrom [Nothing , (K , V ), M [K , V ]]): GenCodec [M [K , V ] with BMap [K , V ]] =
435
- createList[M [K , V ] with BMap [K , V ]](
436
- collectPairsTo[K , V , M [K , V ]],
437
- (lo, map) => map.iterator.foreach({ case (k, v) => writeKVPair(lo.writeElement().writeObject(), k, v) }),
438
- allowNull = true
439
- )
440
-
441
- implicit def fallbackJMapCodec [M [X , Y ] <: JMap [X , Y ], K : GenCodec , V : GenCodec ](
442
- implicit cbf : JCanBuildFrom [(K , V ), M [K , V ]]): GenCodec [M [K , V ] with JMap [K , V ]] =
443
- createList[M [K , V ] with JMap [K , V ]](
444
- collectPairsTo[K , V , M [K , V ]],
445
- (lo, map) => map.asScala.iterator.foreach({ case (k, v) => writeKVPair(lo.writeElement().writeObject(), k, v) }),
446
- allowNull = true
447
- )
448
- }
449
-
450
408
trait RecursiveAutoCodecs { this : GenCodec .type =>
451
409
/**
452
410
* Like `materialize`, but descends into types that `T` is made of (e.g. case class field types).
0 commit comments