Skip to content

Commit c61ae1e

Browse files
committed
Add JsonCodecMaker.makeWithSkipNestedOptionValues
1 parent c410cb5 commit c61ae1e

File tree

4 files changed

+144
-114
lines changed

4 files changed

+144
-114
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,16 @@ object JsonCodecMaker {
507507
*/
508508
def makeWithRequiredDefaultFields[A]: JsonValueCodec[A] = macro Impl.makeWithRequiredDefaultFields[A]
509509

510+
/**
511+
* A replacement for the `make` call with the
512+
* `CodecMakerConfig.withSkipNestedOptionValues(true)`
513+
* configuration parameter.
514+
*
515+
* @tparam A a type that should be encoded and decoded by the derived codec
516+
* @return an instance of the derived codec
517+
*/
518+
def makeWithSkipNestedOptionValues[A]: JsonValueCodec[A] = macro Impl.makeWithSkipNestedOptionValues[A]
519+
510520
/**
511521
* A replacement for the `make` call with the
512522
* `CodecMakerConfig.withTransientEmpty(false).withTransientDefault(false).withTransientNone(false).withDiscriminatorFieldName(None)`
@@ -553,6 +563,9 @@ object JsonCodecMaker {
553563
def makeWithRequiredDefaultFields[A: c.WeakTypeTag](c: blackbox.Context): c.Expr[JsonValueCodec[A]] =
554564
make(c)(CodecMakerConfig.withTransientDefault(false).withRequireDefaultFields(true))
555565

566+
def makeWithSkipNestedOptionValues[A: c.WeakTypeTag](c: blackbox.Context): c.Expr[JsonValueCodec[A]] =
567+
make(c)(CodecMakerConfig.withSkipNestedOptionValues(true))
568+
556569
def makeCirceLike[A: c.WeakTypeTag](c: blackbox.Context): c.Expr[JsonValueCodec[A]] =
557570
make(c)(CodecMakerConfig.withTransientEmpty(false).withTransientDefault(false).withTransientNone(false)
558571
.withDiscriminatorFieldName(None).withCirceLikeObjectEncoding(true))

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,16 @@ object JsonCodecMaker {
557557
*/
558558
inline def makeWithRequiredDefaultFields[A]: JsonValueCodec[A] = ${Impl.makeWithRequiredDefaultFields}
559559

560+
/**
561+
* A replacement for the `make` call with the
562+
* `CodecMakerConfig.withSkipNestedOptionValues(true)`
563+
* configuration parameter.
564+
*
565+
* @tparam A a type that should be encoded and decoded by the derived codec
566+
* @return an instance of the derived codec
567+
*/
568+
inline def makeWithSkipNestedOptionValues[A]: JsonValueCodec[A] = ${Impl.makeWithSkipNestedOptionValues}
569+
560570
/**
561571
* A replacement for the `make` call with the
562572
* `CodecMakerConfig.withTransientEmpty(false).withTransientDefault(false).withTransientNone(false).withDiscriminatorFieldName(None)`
@@ -598,6 +608,9 @@ object JsonCodecMaker {
598608
def makeWithRequiredDefaultFields[A: Type](using Quotes): Expr[JsonValueCodec[A]] =
599609
make(CodecMakerConfig.withTransientDefault(false).withRequireDefaultFields(true))
600610

611+
def makeWithSkipNestedOptionValues[A: Type](using Quotes): Expr[JsonValueCodec[A]] =
612+
make(CodecMakerConfig.withSkipNestedOptionValues(true))
613+
601614
def makeWithRequiredCollectionFieldsAndNameAsDiscriminatorFieldName[A: Type](using Quotes): Expr[JsonValueCodec[A]] =
602615
make(CodecMakerConfig.withTransientEmpty(false).withRequireCollectionFields(true)
603616
.withDiscriminatorFieldName(Some("name")))

0 commit comments

Comments
 (0)