public void SerializesEnumAsString_01() { var jsonOptions = new JsonSerializerSettings(); jsonOptions.ConfigureDefaultJsonSerializerSettings(); var input = new DtoTestClass { EnumProp = TestEnum.Two }; var serialized = JsonConvert.SerializeObject(input, jsonOptions); Assert.Contains("\"Two\"", serialized); }
public void SerializesWithCamelCase() { var jsonOptions = new JsonSerializerSettings(); jsonOptions.ConfigureDefaultJsonSerializerSettings(true); var input = new DtoTestClass { EnumProp = TestEnum.Two }; var serialized = JsonConvert.SerializeObject(input, jsonOptions); Assert.Contains("\"enumProp\"", serialized); }
/// <summary> /// This enables the <see cref="StringEnumConverter"/>, sets <see cref="NullValueHandling"/> to ignore, /// and adds the <see cref="DefaultValuesContractResolver"/> to ignore default values for certain types, e.g. /// Guid.Empty, DateTime.MinValue and DateTimeOffset.MinValue /// </summary> /// <param name="jsonSerializerSettings"></param> public static void ConfigureDefaultJsonSerializerSettings(this JsonSerializerSettings jsonSerializerSettings) { jsonSerializerSettings.ConfigureDefaultJsonSerializerSettings(false); }