Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ public void Serialize_ShouldNotCamelCaseBindVars_WhenSerializingPostCursorBody()

byte[] jsonBytes = serialization.Serialize(body, new ApiClientSerializationOptions(
useCamelCasePropertyNames: true,
ignoreNullValues: true,
camelCasePropertyNamesOfObjectValuesInDictionaries: false));
ignoreNullValues: true));

string jsonString = Encoding.UTF8.GetString(jsonBytes);

Expand All @@ -179,22 +178,22 @@ public void Serialize_ShouldCamelCaseBindVars_WhenSerializingPostCursorBody()
{
BindVars = new Dictionary<string, object>
{
["DontCamelCaseKey"] = new { DontCamelCaseMe = true }
["CamelCaseKey"] = new { CamelCaseMe = true }
}
};
var serialization = new JsonNetApiClientSerialization();

byte[] jsonBytes = serialization.Serialize(body, new ApiClientSerializationOptions(
useCamelCasePropertyNames: true,
ignoreNullValues: true,
camelCasePropertyNamesOfObjectValuesInDictionaries: true));
ignoreNullValues: true,
applySerializationOptionsToObjectValuesInDictionaries: true));

string jsonString = Encoding.UTF8.GetString(jsonBytes);

Assert.Contains("DontCamelCaseKey", jsonString);
Assert.DoesNotContain("dontCamelCaseKey", jsonString);
Assert.Contains("dontCamelCaseMe", jsonString);
Assert.DoesNotContain("DontCamelCaseMe", jsonString);
Assert.Contains("CamelCaseKey", jsonString);
Assert.DoesNotContain("camelCaseKey", jsonString);
Assert.Contains("camelCaseMe", jsonString);
Assert.DoesNotContain("CamelCaseMe", jsonString);
}

[Fact]
Expand All @@ -212,8 +211,7 @@ public void Serialize_ShouldNotCamelCaseParams_WhenSerializingPostTransactionBod

byte[] jsonBytes = serialization.Serialize(body, new ApiClientSerializationOptions(
useCamelCasePropertyNames: true,
ignoreNullValues: true,
camelCasePropertyNamesOfObjectValuesInDictionaries: false));
ignoreNullValues: true));

string jsonString = Encoding.UTF8.GetString(jsonBytes);

Expand All @@ -231,7 +229,7 @@ public void Serialize_ShouldCamelCaseParams_WhenSerializingPostTransactionBody()
{
Params = new Dictionary<string, object>
{
["DontCamelCaseKey"] = new { DontCamelCaseMe = true }
["CamelCaseKey"] = new { CamelCaseMe = true }
}
};

Expand All @@ -240,14 +238,14 @@ public void Serialize_ShouldCamelCaseParams_WhenSerializingPostTransactionBody()
byte[] jsonBytes = serialization.Serialize(body, new ApiClientSerializationOptions(
useCamelCasePropertyNames: true,
ignoreNullValues: true,
camelCasePropertyNamesOfObjectValuesInDictionaries: true));
applySerializationOptionsToObjectValuesInDictionaries: true));

string jsonString = Encoding.UTF8.GetString(jsonBytes);

Assert.Contains("DontCamelCaseKey", jsonString);
Assert.DoesNotContain("dontCamelCaseKey", jsonString);
Assert.Contains("dontCamelCaseMe", jsonString);
Assert.DoesNotContain("DontCamelCaseMe", jsonString);
Assert.Contains("CamelCaseKey", jsonString);
Assert.DoesNotContain("camelCaseKey", jsonString);
Assert.Contains("camelCaseMe", jsonString);
Assert.DoesNotContain("CamelCaseMe", jsonString);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class ApiClientSerialization : IApiClientSerialization
ignoreNullValues: true,
useStringEnumConversion: false,
ignoreMissingMember: true,
camelCasePropertyNamesOfObjectValuesInDictionaries: false);
applySerializationOptionsToObjectValuesInDictionaries: false);

/// <summary>
/// Deserializes the data structure contained by the specified stream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ public class ApiClientSerializationOptions
public bool UseStringEnumConversion { get; set; }

/// <summary>
/// True to camel case the names of properties of object values
/// True to apply serialization options to object values
/// in dictionaries (i.e. CamelCaseMe => "camelCaseMe").
/// False to leave the names of properties of object values
/// in dictionaries as they are (i.e. DontCamelCaseMe => "DontCamelCaseMe")
/// False to not apply serialization options to object values
/// in dictionaries (i.e. leave the names of properties of object values
/// in dictionaries as they are: DontCamelCaseMe => "DontCamelCaseMe")
/// </summary>
public bool CamelCasePropertyNamesOfObjectValuesInDictionaries { get; set; }
public bool ApplySerializationOptionsToObjectValuesInDictionaries { get; set; }

/// <summary>
/// Create serialization options.
Expand All @@ -42,19 +43,19 @@ public class ApiClientSerializationOptions
/// <param name="ignoreNullValues">Whether null values should be ignored - i.e. not defined at all in the serialized string.</param>
/// <param name="useStringEnumConversion">Whether to serialize enum values to a string value instead of an integer.</param>
/// <param name="ignoreMissingMember">Whether missing members should be ignored.</param>
/// <param name="camelCasePropertyNamesOfObjectValuesInDictionaries">Whether to camel case the names of properties of object values in dictionaries.</param>
/// <param name="applySerializationOptionsToObjectValuesInDictionaries">Whether to apply serialization options to object values in dictionaries.</param>
public ApiClientSerializationOptions(
bool useCamelCasePropertyNames,
bool ignoreNullValues,
bool useStringEnumConversion = false,
bool ignoreMissingMember = true,
bool camelCasePropertyNamesOfObjectValuesInDictionaries = false)
bool applySerializationOptionsToObjectValuesInDictionaries = false)
{
UseCamelCasePropertyNames = useCamelCasePropertyNames;
IgnoreNullValues = ignoreNullValues;
UseStringEnumConversion = useStringEnumConversion;
IgnoreMissingMember = ignoreMissingMember;
CamelCasePropertyNamesOfObjectValuesInDictionaries = camelCasePropertyNamesOfObjectValuesInDictionaries;
ApplySerializationOptionsToObjectValuesInDictionaries = applySerializationOptionsToObjectValuesInDictionaries;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
{
// Use a local serializer for writing instead of the passed-in serializer
JsonSerializer mySerializer;
if (_serializationOptions != null && _serializationOptions.CamelCasePropertyNamesOfObjectValuesInDictionaries)
if (_serializationOptions != null && _serializationOptions.ApplySerializationOptionsToObjectValuesInDictionaries)
{
mySerializer = new JsonSerializer
{
Expand Down