Error in Spring.Reflection TType.SetMemberValue when using Guid column

Issue #95 resolved
Diego Garcia created an issue

Hi guys I'm starting to play with marshmallow and writing some demos, the first one I've setup one of my postgresql database using firedac, the test table primary key used is a uid field that I've mapped to my model class as a TGUID.

When starting the application I'm getting an EInvalidCast with message "invalid class typecast", so after tracking the callstack I've founded that it has a TODO on SetMemberValue asking for adding conversion to TValue, I think we will need to take care of a guid type to string on mapping to avoid this errors.

I can work around to continue my tests now but did you guys need a help to test other types ? I could help on that while I'm studing the framework to better understand.

Best Regards, Diego Garcia

Comments (9)

  1. Stefan Glienke repo owner

    Currently only built-in types are supported - for the future (as in not for 1.2) we might use the value converters for that.

  2. Diego Garcia reporter

    Nice to know Stefan I will do in my fork an implementation of the value converter then I send it to you do a code review ;)

  3. Stefan Glienke repo owner

    Today I continued the refactoring for #46 and added a TryConvert method to the TValueHelper. It has some type conversion built-in but falls back to the registered value converters (which are also being refactored - especially the retrieval of the correct one for the given types).

    With these changes I was able to retrieve a uniqueidentifier column from an MSSQL database (which was returned in a TWideStringField) into a TGuid property and update the entity. I needed to add a string-to-TGuid and a TGuid-to-Variant converter. That is because currently the frameworks turns the variant from the field into a TValue using FromVariant which then stores it as a string inside the TValue. And then it needs to turn that into the type of the property.

    My goal is to make that just one conversion from the Variant directly to the type of the property (just like the other way around).

  4. Stefan Glienke repo owner

    I recently added string<->guid conversion so this should work now.

    I tested with MSSQL and a uniqueidentifier column and an entity class with data type TGUID but as no sql specific code was changed but only the type conversion was added it should also work for other databases where a guid is returned in a string field (using typical delphi formatting with curly brackets).

  5. Log in to comment