@@ -663,6 +663,70 @@ func TestJSONSchemaSerdeWithCELFieldTransformWithDef(t *testing.T) {
663
663
serde .MaybeFail ("deserialization" , err , serde .Expect (& newobj , & obj2 ))
664
664
}
665
665
666
+ func TestJSONSchemaSerdeWithCELFieldTransformWithSimpleMap (t * testing.T ) {
667
+ serde .MaybeFail = serde .InitFailFunc (t )
668
+ var err error
669
+
670
+ conf := schemaregistry .NewConfig ("mock://" )
671
+
672
+ client , err := schemaregistry .NewClient (conf )
673
+ serde .MaybeFail ("Schema Registry configuration" , err )
674
+
675
+ serConfig := NewSerializerConfig ()
676
+ serConfig .AutoRegisterSchemas = false
677
+ serConfig .UseLatestVersion = true
678
+ ser , err := NewSerializer (client , serde .ValueSerde , serConfig )
679
+ serde .MaybeFail ("Serializer configuration" , err )
680
+
681
+ encRule := schemaregistry.Rule {
682
+ Name : "test-cel" ,
683
+ Kind : "TRANSFORM" ,
684
+ Mode : "WRITE" ,
685
+ Type : "CEL_FIELD" ,
686
+ Expr : "name == 'StringField' ; value + '-suffix'" ,
687
+ }
688
+ ruleSet := schemaregistry.RuleSet {
689
+ DomainRules : []schemaregistry.Rule {encRule },
690
+ }
691
+
692
+ info := schemaregistry.SchemaInfo {
693
+ Schema : demoSchema ,
694
+ SchemaType : "JSON" ,
695
+ RuleSet : & ruleSet ,
696
+ }
697
+
698
+ id , err := client .Register ("topic1-value" , info , false )
699
+ serde .MaybeFail ("Schema registration" , err )
700
+ if id <= 0 {
701
+ t .Errorf ("Expected valid schema id, found %d" , id )
702
+ }
703
+
704
+ obj := make (map [string ]interface {})
705
+ obj ["IntField" ] = 123
706
+ obj ["DoubleField" ] = 45.67
707
+ obj ["StringField" ] = "hi"
708
+ obj ["BoolField" ] = true
709
+ obj ["BytesField" ] = base64 .StdEncoding .EncodeToString ([]byte {0 , 0 , 0 , 1 })
710
+ bytes , err := ser .Serialize ("topic1" , & obj )
711
+ serde .MaybeFail ("serialization" , err )
712
+
713
+ deser , err := NewDeserializer (client , serde .ValueSerde , NewDeserializerConfig ())
714
+ serde .MaybeFail ("Deserializer configuration" , err )
715
+ deser .Client = ser .Client
716
+
717
+ obj2 := JSONDemoSchema {}
718
+ // JSON decoding produces floats
719
+ obj2 .IntField = 123.0
720
+ obj2 .DoubleField = 45.67
721
+ obj2 .StringField = "hi-suffix"
722
+ obj2 .BoolField = true
723
+ obj2 .BytesField = base64 .StdEncoding .EncodeToString ([]byte {0 , 0 , 0 , 1 })
724
+
725
+ var newobj JSONDemoSchema
726
+ err = deser .DeserializeInto ("topic1" , bytes , & newobj )
727
+ serde .MaybeFail ("deserialization" , err , serde .Expect (& newobj , & obj2 ))
728
+ }
729
+
666
730
func TestJSONSchemaSerdeWithCELFieldTransformComplex (t * testing.T ) {
667
731
serde .MaybeFail = serde .InitFailFunc (t )
668
732
var err error
0 commit comments