FastEasyMapping icon indicating copy to clipboard operation
FastEasyMapping copied to clipboard

FEMRelationship conditional FEMMapping

Open pavlonadolynskyi opened this issue 7 years ago • 3 comments

Hi! I have a question about ability of FastEasyMapping to map relationship with different inner classes. I.e. I have a Questionnaire and it has 'questions' relation, but each question can be QuestionOpen or QuestionSelection, I can designate which class is that by 'type' property. @dimazen How can I achieve that?

pavlonadolynskyi avatar Dec 19 '16 14:12 pavlonadolynskyi

Hello, @pablucco It is kind of a dynamic mapping that can be found on RestKit. Unfortunately it is not implemented and therefore you won't be able to do so.

However I can take a look in the evening how much effort it'll take to implement it. It should be fairly simple to do.

dimazen avatar Dec 20 '16 08:12 dimazen

@dimazen It would be so great! How are you planning to implement that? I mean will that cause architecture changes?

pavlonadolynskyi avatar Dec 20 '16 14:12 pavlonadolynskyi

@pablucco hello there.I was digging into it and here are few thoughts:

  • we need to dynamically evaluate what mapping for the given JSON. The best way is to use blocks.
  • it is useful to add dynamic keyPath evaluation as well.

Most rough solution looks like adding block to the FEMMapping itself, that will evaluate given JSON and return FEMRelationship with correct values. I'm not quite sure, but it looks a little bit ugly to me. What do you think?

I mean will that cause architecture changes?

I don't think so. Probably we'll have few more methods on FEMMapping and some internal changes for FEMDeserializer.

dimazen avatar Dec 22 '16 08:12 dimazen