Skip to content

Commit

Permalink
Fix 9332
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo authored and marek-safar committed Jul 9, 2018
1 parent 5bc264a commit dc56ae2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions mcs/class/System.Runtime.Serialization/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ LIB_MCS_FLAGS = \
$(RESOURCE_FILES:%=/resource:%)
TXT_RESOURCE_STRINGS = ../referencesource/System.Runtime.Serialization/System.Runtime.Serialization.txt

XTEST_LIB_REFS = System System.Core System.Xml System.Xml.Linq System.Drawing Facades/System.Threading.Tasks

ifneq (2.1, $(FRAMEWORK_VERSION))
LIB_REFS += System.Data System.Configuration SMDiagnostics
LIB_MCS_FLAGS += /d:NET_3_0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,9 @@ void ReadSimpleDictionary (CollectionDataContract collectionContract, Type keyVa
var jsonMemberName = XmlObjectSerializerReadContextComplexJson.GetJsonMemberName (xmlReader);
object key = null;

if (keyParseMode == KeyParseMode.UsingParseEnum)
if (keyParseMode == KeyParseMode.AsString)
key = jsonMemberName;
else if (keyParseMode == KeyParseMode.UsingParseEnum)
key = Enum.Parse (keyType, jsonMemberName);
else if (keyParseMode == KeyParseMode.UsingCustomParse)
key = keyDataContract.ParseMethod.Invoke (null, new object [] {jsonMemberName});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#../../../external/corefx/src/System.Runtime.Serialization.Json/tests/DataContractJsonSerializer.cs
../../../external/corefx/src/System.Runtime.Serialization.Xml/tests/SerializationTypes.cs
../../../external/corefx/src/System.Runtime.Serialization.Xml/tests/SerializationTypes.RuntimeOnly.cs
../../../external/corefx/src/Common/tests/System/Runtime/Serialization/Utils.cs
../../../external/corefx/src/CoreFx.Private.TestUtilities/src/System/AssertExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -879,5 +879,30 @@ public void IEnumerableTest ()
Assert.AreEqual (typeof (string []), result.GetType ());
}
}

[Test] //https://github.com/mono/mono/issues/9332
public void SimpleStringDictionaryTest ()
{
string json = "{\"key\": \"value\"}";

// Dictionary<string, string>:
using (var stream = new MemoryStream (Encoding.UTF8.GetBytes (json))) {
var serializer = new DataContractJsonSerializer (typeof (Dictionary<string, string>),
new DataContractJsonSerializerSettings { UseSimpleDictionaryFormat = true });

var obj = serializer.ReadObject (stream) as Dictionary<string, string>;
Assert.AreEqual ("value", obj ["key"]);
}

// Dictionary<int, string>:
json = "{\"42\": \"value\"}";
using (var stream = new MemoryStream (Encoding.UTF8.GetBytes (json))) {
var serializer = new DataContractJsonSerializer (typeof (Dictionary<int, string>),
new DataContractJsonSerializerSettings { UseSimpleDictionaryFormat = true });

var obj = serializer.ReadObject (stream) as Dictionary<int, string>;
Assert.AreEqual ("value", obj [42]);
}
}
}
}
1 change: 1 addition & 0 deletions scripts/ci/run-test-default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ ${TESTCMD} --label=System.Data.DSE --timeout=5m make -w -C mcs/class/System.Data
${TESTCMD} --label=System.Web.Abstractions --timeout=5m make -w -C mcs/class/System.Web.Abstractions run-test
${TESTCMD} --label=System.Web.Routing --timeout=5m make -w -C mcs/class/System.Web.Routing run-test
${TESTCMD} --label=System.Runtime.Serialization --timeout=5m make -w -C mcs/class/System.Runtime.Serialization run-test
${TESTCMD} --label=System.Runtime.Serialization-xunit --timeout=5m make -w -C mcs/class/System.Runtime.Serialization run-xunit-test
${TESTCMD} --label=System.IdentityModel --timeout=5m make -w -C mcs/class/System.IdentityModel run-test
${TESTCMD} --label=System.ServiceModel --timeout=15m make -w -C mcs/class/System.ServiceModel run-test
${TESTCMD} --label=System.ServiceModel.Web --timeout=5m make -w -C mcs/class/System.ServiceModel.Web run-test
Expand Down

0 comments on commit dc56ae2

Please sign in to comment.