View Full Version : [CLOSED] How to send dictionary(of string, string) as clientconfig?

Nov 10, 2008, 4:45 PM
I created a DialogWindow class that inherits from Coolite.Window that has an associated clientside Ext.ux.DialogWindow class. In the client class, I have a params property that's just an object. How can I create a clientconfig serverside property in my DialogWindow class that will serialize correctly? I tried:

Private _URLParams As New Dictionary(Of String, String)
''' <summary>
''' Query string parameters to send to dialog
''' </summary>
<ClientConfig("urlParams", JsonMode.UnrollCollection)> _
<DefaultValue(CType(Nothing, Object))> _
<Category("Config Options")> _
Public Property URLParams() As Dictionary(Of String, String)
Return _URLParams
End Get
Set(ByVal value As Dictionary(Of String, String))
_URLParams = value
End Set
End Property

However, I don't see it as part of the rendered script. Is there anything special I need to do? In ASP.NET, dictionary(of string, string) is serialized as a javascript object.

Nov 10, 2008, 5:12 PM
Argh...I always find the answer AFTER I make a post about it. Please let me know if this is the right way to do it. I basically created my own StringDictionaryJsonConverter:

Public Class StringDictionaryJsonConverter
Inherits JsonConverter

Public Overloads Overrides Function CanConvert(ByVal valueType As Type) As Boolean
Return GetType(Dictionary(Of String, String)).IsAssignableFrom(valueType)
End Function

Public Overloads Overrides Sub WriteJson(ByVal writer As JsonWriter, ByVal value As Object)
Dim dictionary As Dictionary(Of String, String) = TryCast(value, Dictionary(Of String, String))
If dictionary IsNot Nothing Then
Dim iterator As Dictionary(Of String, String).Enumerator = dictionary.GetEnumerator()

While iterator.MoveNext()
End While

End If
End Sub

Public Overloads Overrides Function ReadJson(ByVal reader As Newtonsoft.Json.JsonReader, ByVal objectType As Type) As Object
Throw New NotImplementedException()
End Function

End Class

Nov 10, 2008, 5:26 PM
I originally used LoadConfig.Params as an example so is that a bug?

Dictionary<string, string> paramItems = new Dictionary<string, string>();

[Description("Custom list of parameters passed to the url.")]
public virtual Dictionary<string, string> Params
return this.paramItems;
this.paramItems = value;

Nov 12, 2008, 6:16 AM

I don't think that is a bug. With Mode Json.UnrollCollection the ClientConfig builder try to serialize each item of collection to one object. The item of Dictionary is KeyValuePair which don't have properties with ClientConfig attribute (please note that only such properties can handled by ClientConfig builder). Therefore serialization for dictionary is empty

I think that your solution with JsonConverter is good.

Hope this help