Closed izN8nu6RyeneG5XnBoBgyRMVGH6H43WF closed 1 year ago
Finally, new real issue. Thank you for sharing it I'll take a look
Thank you so much for a good case, which is now covered. 🎉
@k-paxian The linked fix looks like it should work in the usual use case. However, since it's really just looking for valid JSON, it may still encounter issues for String discriminatorProperty fields representing something other than a Type, e.g. suppose we want to discriminate based on an arbitrary String. If that String just so happens to be JSON, it may not behave as the developer expects.
Most people probably won't use it that way, but it might be worth documenting.
@izN8nu6RyeneG5XnBoBgyRMVGH6H43WF No worries, String based discriminators are working as expected. Please take a look at 6d8da09ea7f034483fb00996d5a88fdeb7ee52a6 test. Thank you for your details oriented attitude and useful hints so far 👍
Version: 2.2.5+3
I'm using a getter to runtimeType as a subclass discriminator, with the default discriminator subclass values, the class name. The value appears to be correctly serialized. However, when deserializing, an uncaught JsonFormatError is thrown.
Example:
Analysis:
The error is thrown in mapper.dart in _deserializeObject:
https://github.com/k-paxian/dart-json-mapper/blob/e954ddcff8ca675271cf518c107a2340949ab830/mapper/lib/src/mapper.dart#L892-L898
The logic (probably correctly) always attempts to decode jsonValue as JSON if it is a String, which makes sense, since we're supposed to be passing JSON. However, the calling function, _detectObjectType, is passing in the String value, not the JSON representation of it:
https://github.com/k-paxian/dart-json-mapper/blob/e954ddcff8ca675271cf518c107a2340949ab830/mapper/lib/src/mapper.dart#L327-L342
Maybe calling function valuates Strings one too many times, i.e. at line 331?