mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 15:55:54 +01:00
Exception handling when receiving value that does not exist in the mapped values.
Search for mapped values case insensitive
This commit is contained in:
parent
782bf2c4e0
commit
cd162c5977
@ -314,7 +314,8 @@ uses
|
|||||||
MVCFramework.Serializer.JsonDataObjects,
|
MVCFramework.Serializer.JsonDataObjects,
|
||||||
MVCFramework.Serializer.Intf,
|
MVCFramework.Serializer.Intf,
|
||||||
Data.FmtBcd,
|
Data.FmtBcd,
|
||||||
MVCFramework.Nullables;
|
MVCFramework.Nullables,
|
||||||
|
System.Generics.Defaults;
|
||||||
|
|
||||||
function NewObjectHolder(const AObject: TObject; const AMetaFiller: TProc<TMVCStringDictionary> = nil;
|
function NewObjectHolder(const AObject: TObject; const AMetaFiller: TProc<TMVCStringDictionary> = nil;
|
||||||
const AOwns: boolean = false): TMVCObjectResponse;
|
const AOwns: boolean = false): TMVCObjectResponse;
|
||||||
@ -732,7 +733,12 @@ end;
|
|||||||
constructor MVCEnumSerializationAttribute.Create(const ASerializationType: TMVCEnumSerializationType;
|
constructor MVCEnumSerializationAttribute.Create(const ASerializationType: TMVCEnumSerializationType;
|
||||||
const AMappedValues: string);
|
const AMappedValues: string);
|
||||||
begin
|
begin
|
||||||
FMappedValues := TList<string>.Create;
|
FMappedValues := TList<string>.Create(TDelegatedComparer<string>.Create(
|
||||||
|
function(const Left, Right: string): Integer
|
||||||
|
begin
|
||||||
|
Result := CompareText(Left, Right);
|
||||||
|
end));
|
||||||
|
|
||||||
FSerializationType := ASerializationType;
|
FSerializationType := ASerializationType;
|
||||||
|
|
||||||
if (FSerializationType = estEnumMappedValues) then
|
if (FSerializationType = estEnumMappedValues) then
|
||||||
|
@ -936,6 +936,9 @@ begin
|
|||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
LMappedValueIndex := LEnumMappedValues.IndexOf(AJsonObject[AName].Value);
|
LMappedValueIndex := LEnumMappedValues.IndexOf(AJsonObject[AName].Value);
|
||||||
|
if LMappedValueIndex < 0 then
|
||||||
|
raise EMVCSerializationException.CreateFmt('Cannot deserialize property %s from mapped values', [AName]);
|
||||||
|
|
||||||
TValue.Make(GetEnumValue(AValue.TypeInfo, GetEnumName(AValue.TypeInfo, LMappedValueIndex)),
|
TValue.Make(GetEnumValue(AValue.TypeInfo, GetEnumName(AValue.TypeInfo, LMappedValueIndex)),
|
||||||
AValue.TypeInfo, AValue)
|
AValue.TypeInfo, AValue)
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user