delphi-rest-client-api
delphi-rest-client-api copied to clipboard
Unmarshal to TDictionary
I can't unmarshal JSON
{
"data": {
"1": "value one",
"2": "value two"
}
}
into class:
TDictionaryDataObject = class
data: TDictionary<string, string>;
end;
Should it work?
I don't think so.
The parser will find for fields and properties to make the mapping. I guess the TDictionary approach is not supported, but, I am not sure.
It's not supported in SuperObject. Would like to see it supported. But then again, how often is it that the fields are of the same type?
Had it been:
{
"data": {
"1": "value one",
"2": 1
}
}
The TDictionary would have to be defined with a variant, so i don't know how useful it would be.
I've had this problem one time before. Had no need for changing the data so I used my own JSON parser.
It would be cool if you could specify the type as a TSuperObject:
TDictionaryDataObject = class
data: TSuperObject;
end;
@Frees It's currently not supported. But i think it's possible, just using the same approach as for List<T>.
@thomaserlang I believe works using ISuperObject (the interface).It would good write a test for verify this behaviour. https://github.com/fabriciocolombo/delphi-rest-client-api/blob/master/lib/superobject/superobject.pas#L7123-L7125
Ah, cool. That does indeed work.
Hi @thomaserlang can you give me an example of it working?
What are you referring to @Timothyoverton? SuperObject?
Just use ISuperObject
instead of TSuperObject
in the class definition.
TDictionaryDataObject = class
data: ISuperObject;
end;