@@ -30,13 +30,14 @@ public static async Task WriteTemplateAsync(TextWriter writer, Entity entity, Te
3030 await WriteObjectAsync ( jw , entity , templateValueMap , annotateAsResource : true ) ;
3131 }
3232
33- static async Task WriteValueAsync ( JsonWriter jw , object ? v , TemplateValueMap templateValueMap )
33+ static async Task WriteValueAsync ( JsonWriter jw , object ? v , TemplateValueMap templateValueMap , PropertyInfo ? enclosingProperty = null )
3434 {
3535 await ( v switch
3636 {
3737 null => jw . WriteNullAsync ( ) ,
3838 string s => jw . WriteValueAsync ( s ) ,
39- IEnumerable a => WriteArrayAsync ( jw , a , templateValueMap ) ,
39+ IReadOnlyDictionary < string , string > ds => WriteDictionaryAsync ( jw , ds , templateValueMap , enclosingProperty ) ,
40+ IEnumerable a => WriteArrayAsync ( jw , a , templateValueMap , enclosingProperty ) ,
4041 var o when o . GetType ( ) . IsClass => WriteObjectAsync ( jw , o , templateValueMap ) ,
4142 var e when e . GetType ( ) . IsEnum => jw . WriteValueAsync ( e . ToString ( ) ) ,
4243 _ => jw . WriteValueAsync ( v )
@@ -63,10 +64,31 @@ static async Task WriteArrayAsync(JsonWriter jw, object a, TemplateValueMap temp
6364 await jw . WriteEndArrayAsync ( ) ;
6465 }
6566
66- static async Task WriteObjectAsync ( JsonWriter jw , object o , TemplateValueMap templateValueMap , bool annotateAsResource = false )
67+ static async Task WriteDictionaryAsync ( JsonWriter jw , IReadOnlyDictionary < string , string > ds , TemplateValueMap templateValueMap , PropertyInfo ? enclosingProperty = null )
6768 {
6869 await jw . WriteStartObjectAsync ( ) ;
6970
71+ foreach ( var ( k , v ) in ds )
72+ {
73+ await jw . WritePropertyNameAsync ( k ) ;
74+
75+ if ( enclosingProperty != null &&
76+ templateValueMap . TryGetRawElement ( enclosingProperty , v , out var raw ) )
77+ {
78+ await jw . WriteRawValueAsync ( raw ) ;
79+ }
80+ else
81+ {
82+ await WriteValueAsync ( jw , v , templateValueMap ) ;
83+ }
84+ }
85+
86+ await jw . WriteEndObjectAsync ( ) ;
87+ }
88+
89+ static async Task WriteObjectAsync ( JsonWriter jw , object o , TemplateValueMap templateValueMap , bool annotateAsResource = false )
90+ {
91+ await jw . WriteStartObjectAsync ( ) ;
7092
7193 if ( annotateAsResource )
7294 {
@@ -76,6 +98,9 @@ static async Task WriteObjectAsync(JsonWriter jw, object o, TemplateValueMap tem
7698
7799 foreach ( var ( pi , v ) in GetTemplateProperties ( o ) )
78100 {
101+ if ( templateValueMap . IsIgnored ( pi ) )
102+ continue ;
103+
79104 var pa = pi . GetCustomAttribute < JsonPropertyAttribute > ( ) ;
80105 if ( pa ? . DefaultValueHandling == DefaultValueHandling . Ignore &&
81106 v == null || v as int ? == 0 || v as decimal ? == 0m || v as uint ? == 0 )
@@ -87,10 +112,8 @@ static async Task WriteObjectAsync(JsonWriter jw, object o, TemplateValueMap tem
87112
88113 if ( templateValueMap . TryGetRawValue ( pi , v , out var raw ) )
89114 await jw . WriteRawValueAsync ( raw ) ;
90- else if ( v is not string && v is IEnumerable )
91- await WriteArrayAsync ( jw , v , templateValueMap , pi ) ;
92115 else
93- await WriteValueAsync ( jw , v , templateValueMap ) ;
116+ await WriteValueAsync ( jw , v , templateValueMap , pi ) ;
94117 }
95118
96119 await jw . WriteEndObjectAsync ( ) ;
0 commit comments