Skip to content

Commit e389fe8

Browse files
committed
Fix map keys order inconsistency.
This commit fixes the issue that map keys order emitted by asymmetric (serialization only) serializer are inconsistent across platform because they are not sorted due to incorrect flow.
1 parent c210cd6 commit e389fe8

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,4 +750,4 @@ Release 1.0.0
750750

751751
BUG FIXES
752752
* [NonSerialized] attribute does not effect in Mono based platform including Unity.
753-
753+
* Fix map keys order emitted by asymmetric (serialization only) serializer are inconsistent across platform.

src/MsgPack/Serialization/SerializationTarget.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public static SerializationTarget Prepare( SerializationContext context, Type ta
193193

194194
var memberCandidates = getters.Where( entry => CheckTargetEligibility( context, entry.Member ) ).ToArray();
195195

196-
if ( memberCandidates.Length == 0 )
196+
if ( memberCandidates.Length == 0 && !context.CompatibilityOptions.AllowAsymmetricSerializer )
197197
{
198198
ConstructorKind constructorKind;
199199
var deserializationConstructor = FindDeserializationConstructor( context, targetType, out constructorKind );
@@ -226,6 +226,15 @@ public static SerializationTarget Prepare( SerializationContext context, Type ta
226226
constructor = deserializationConstructor;
227227
canDeserialize = null;
228228
}
229+
else if ( memberCandidates.Length == 0 )
230+
{
231+
#if DEBUG
232+
Contract.Assert( context.CompatibilityOptions.AllowAsymmetricSerializer );
233+
#endif // DEBUG
234+
// Absolutely cannot deserialize in this case.
235+
canDeserialize = false;
236+
constructorKind = ConstructorKind.Ambiguous;
237+
}
229238
else
230239
{
231240
constructorKind = ConstructorKind.Default;
@@ -243,7 +252,7 @@ public static SerializationTarget Prepare( SerializationContext context, Type ta
243252
canDeserialize = true;
244253
}
245254

246-
if ( constructor != null && constructor.GetParameters().Any() )
255+
if ( constructor != null && constructor.GetParameters().Any() || context.CompatibilityOptions.AllowAsymmetricSerializer )
247256
{
248257
// Recalculate members because getter-only/readonly members should be included for constructor deserialization.
249258
memberCandidates = getters;

0 commit comments

Comments
 (0)