은 nullable 형식 ServiceStack TypeSerializer.DeserializeFromString 버그
에 관한 ServiceStack 방법 TypeSerializer.DeserializeFromString에 버그가있는 것 같습니다이 알려진 문제인가? 수정 프로그램이나 해결 방법이 있습니까?어떤 직렬화 에러 예외 투사를 적용하는 JsConfig 범위를 포함하는 다음 코드 고려해
public class MeasurementsData
{
public int? FlowLeft { get; set; }
public int? FlowRight { get; set; }
public Single? RatioLeft { get; set; }
public Single? RatioRight { get; set; }
}
.
.
.
var originalData = "{FlowRight:970045,RatioRight:null}";
object afterConversionData = null;
try
{
using (var scope = JsConfig.BeginScope())
{
scope.ThrowOnDeserializationError = true;
afterConversionData =TypeSerializer.DeserializeFromString(originalData.ToString() ,typeof(MeasurementsData));
}
}
catch (System.Runtime.Serialization.SerializationException ex)
{
Logger.Warn("Service exception", ex);
}
가 가변적이고 originalData 내부 JSON 예외를 (아래에서 설명) 원인 " 'RatioRight를'속성을 설정하는 데 실패 'null'로 표시됩니다. 'RatioRight'가 'nullable single'이고 'null'이 유효한 값 임에도 불구하고 이런 현상이 발생합니다.
scope.ThrowOnDeserializationError = true
을 제거하는 것은 서버 측에서받은 데이터의 유효성 검사가 필요하기 때문에 "작동"하지만 옵션이 아닙니다. ThrowOnDeserializationError
을 false (기본값)로 설정하면이 특정 경우에는 오류가 발생하지 않지만 다음과 같이 json을 전송할 수 있습니다. {FlowRight:970045,RatioRight:fdfd}
DeserializeFromString의 결과로 인해 예외는 'fdfd'는 단일 null을 허용하지 않습니다. 예외가 내부적으로 처리되어 대신 null이 설정되어 서버가 전송 된 데이터가 유효하지 않고 나중에 db에있는 값 대신 null 값을 저장하게됩니다 (
출처 : ServiceStack.Text
Exception: Failed to set property 'MeasurementData' with '{FlowRight:970045,RatioRight:null}' InnerException: Failed to set property 'RatioRight' with 'null'
StackTrace: at ServiceStack.Text.Common.DeserializeTypeRefJsv.StringToType(TypeConfig typeConfig, String strType, EmptyCtorDelegate ctorFn, Dictionary'2 typeAccessorMap) at ServiceStack.Text.Common.DeserializeType'1.<>c__DisplayClass3.b__2(String value) at ServiceStack.Text.TypeSerializer.DeserializeFromString(String value, Type type) at Site.Service.Services.DataDomainService.Any(SaveDataDomainRequest request) in D:\Service\API Services\Domain\Services\DataDomainService.cs:line 93