@@ -303,7 +303,7 @@ object JsonCodecSpec extends ZIOSpecDefault {
303303 charSequenceToByteChunk(""" {"oneOf":{"_type":"StringValue2","value":"foo2"}}""" )
304304 )
305305 },
306- test(" case class " ) {
306+ test(" transient field annotation " ) {
307307 assertEncodes(
308308 searchRequestWithTransientFieldSchema,
309309 SearchRequestWithTransientField (" foo" , 10 , 20 , " bar" ),
@@ -431,7 +431,7 @@ object JsonCodecSpec extends ZIOSpecDefault {
431431 suite(" Generic Record" )(
432432 test(" Do not encode transient field" ) {
433433 assertEncodes(
434- RecordExample .schema.annotate(rejectExtraFields()) ,
434+ RecordExample .schema,
435435 RecordExample (f1 = Some (" test" ), f3 = Some (" transient" )),
436436 charSequenceToByteChunk(
437437 """ {"$f1":"test"}""" .stripMargin
@@ -836,13 +836,31 @@ object JsonCodecSpec extends ZIOSpecDefault {
836836 JsonError .Message (" duplicate" ) :: Nil
837837 )
838838 },
839- test(" transient field annotation" ) {
839+ test(" transient field annotation with default value in class definition " ) {
840840 assertDecodes(
841841 searchRequestWithTransientFieldSchema,
842- SearchRequestWithTransientField (" test" , 0 , 10 , Schema [ String ].defaultValue.getOrElse( " " ) ),
842+ SearchRequestWithTransientField (" test" , 0 , 10 ),
843843 charSequenceToByteChunk(""" {"query":"test","pageNumber":0,"resultPerPage":10}""" )
844844 )
845845 },
846+ test(" transient field annotation with default value implicitly available for the field type" ) {
847+ case class CaseClassWithTransientField (transient : String )
848+ assertDecodes(
849+ Schema .CaseClass1 [String , CaseClassWithTransientField ](
850+ id0 = TypeId .fromTypeName(" SearchRequestWithTransientField" ),
851+ field0 = Schema .Field (
852+ name0 = " transient" ,
853+ schema0 = Schema [String ],
854+ get0 = _.transient,
855+ set0 = (x, transient) => x.copy(transient = transient),
856+ annotations0 = Chunk (new transientField())
857+ ),
858+ defaultConstruct0 = new CaseClassWithTransientField (_)
859+ ),
860+ CaseClassWithTransientField (Schema [String ].defaultValue.toOption.get),
861+ charSequenceToByteChunk(""" {}""" )
862+ )
863+ },
846864 test(" fieldDefaultValue" ) {
847865 assertDecodes(
848866 fieldDefaultValueSearchRequestSchema,
@@ -878,6 +896,13 @@ object JsonCodecSpec extends ZIOSpecDefault {
878896 charSequenceToByteChunk(""" {"foo":"s","bar":null}""" )
879897 )
880898 },
899+ test(" with transient fields encoded as implicitly available schema default values" ) {
900+ assertDecodes(
901+ recordWithTransientSchema,
902+ ListMap [String , Any ](" foo" -> " " , " bar" -> 0 ),
903+ charSequenceToByteChunk(""" {}""" )
904+ )
905+ },
881906 test(" case class with option fields encoded as null" ) {
882907 assertDecodes(
883908 WithOptionFields .schema,
@@ -2015,7 +2040,7 @@ object JsonCodecSpec extends ZIOSpecDefault {
20152040 query : String ,
20162041 pageNumber : Int ,
20172042 resultPerPage : Int ,
2018- @ transientField nextPage : String = " "
2043+ @ transientField nextPage : String = " transient "
20192044 )
20202045
20212046 val searchRequestWithTransientFieldSchema : Schema [SearchRequestWithTransientField ] =
@@ -2059,6 +2084,25 @@ object JsonCodecSpec extends ZIOSpecDefault {
20592084 )
20602085 )
20612086
2087+ val recordWithTransientSchema : Schema [ListMap [String , _]] = Schema .record(
2088+ TypeId .Structural ,
2089+ Schema .Field (
2090+ " foo" ,
2091+ Schema .Primitive (StandardType .StringType ),
2092+ annotations0 = Chunk (transientField()),
2093+ get0 = (p : ListMap [String , _]) => p(" foo" ).asInstanceOf [String ],
2094+ set0 = (p : ListMap [String , _], v : String ) => p.updated(" foo" , v)
2095+ ),
2096+ Schema
2097+ .Field (
2098+ " bar" ,
2099+ Schema .Primitive (StandardType .IntType ),
2100+ annotations0 = Chunk (transientField()),
2101+ get0 = (p : ListMap [String , _]) => p(" bar" ).asInstanceOf [Int ],
2102+ set0 = (p : ListMap [String , _], v : Int ) => p.updated(" bar" , v)
2103+ )
2104+ )
2105+
20622106 val nestedRecordSchema : Schema [ListMap [String , _]] = Schema .record(
20632107 TypeId .Structural ,
20642108 Schema .Field (
0 commit comments