Skip to content

Commit 4f6e56d

Browse files
committed
Reduce size of generated code when using CodecMakerConfig.withEncodingOnly(true)
1 parent c43a01e commit 4f6e56d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

jsoniter-scala-macros/shared/src/main/scala-2/com/github/plokhotnyuk/jsoniter_scala/macros/JsonCodecMaker.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2307,7 +2307,10 @@ object JsonCodecMaker {
23072307
@_root_.java.lang.SuppressWarnings(_root_.scala.Array("org.wartremover.warts.All"))
23082308
val x = new _root_.com.github.plokhotnyuk.jsoniter_scala.core.JsonValueCodec[$rootTpe] {
23092309
@_root_.scala.inline
2310-
def nullValue: $rootTpe = ${genNullValue(rootTpe :: Nil)}
2310+
def nullValue: $rootTpe = ${
2311+
if (cfg.encodingOnly) q"_root_.scala.Predef.???"
2312+
else genNullValue(rootTpe :: Nil)
2313+
}
23112314

23122315
@_root_.scala.inline
23132316
def decodeValue(in: _root_.com.github.plokhotnyuk.jsoniter_scala.core.JsonReader, default: $rootTpe): $rootTpe = ${

jsoniter-scala-macros/shared/src/main/scala-3/com/github/plokhotnyuk/jsoniter_scala/macros/JsonCodecMaker.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3111,7 +3111,10 @@ object JsonCodecMaker {
31113111
val codecDef = '{ // FIXME: generate a type class instance using `ClassDef.apply` and `Symbol.newClass` calls after graduating from experimental API: https://www.scala-lang.org/blog/2022/06/21/scala-3.1.3-released.html
31123112
new JsonValueCodec[A] {
31133113
@inline
3114-
def nullValue: A = ${genNullValue[A](List(rootTpe))}
3114+
def nullValue: A = ${
3115+
if (cfg.encodingOnly) '{ ??? }
3116+
else genNullValue[A](List(rootTpe))
3117+
}
31153118

31163119
@inline
31173120
def decodeValue(in: JsonReader, default: A): A = ${

0 commit comments

Comments
 (0)