Git Product home page Git Product logo

Comments (4)

dimazen avatar dimazen commented on September 20, 2024

Hello, @fedser.
Could you please share an example of the JSON and mapping for me to better understand (few fields will be more than enough). As far as I understood, you want to skip creation of the instance if one of the keys is not presented?

from fasteasymapping.

fedser avatar fedser commented on September 20, 2024

Here are example of part json:
{"result":[{"id":"234242342","name":"Pack 9","rightContactLensArticle":{"type":"ContactLens","productName":"Product 1","lifecycleState":"Active","supplierDeliveryTime":1440,"storageType":"None","isDeliverable":false,"package":{"size":3,"unit":"Pieces"},"price":{"currency":"EUR","grossAmount":12.59},"id":"22222222"},"rightOpticalSpecification":{"diameter":14,"radiusBaseCurve":8.6,"sphere":-4,"addition":1},"activatedForOnline":true,"createdAt":"2015-01-01T09:09:27.7690000Z"} ]}

In "result" there list of ContactLensInfo. Please notice that now in json we receive "rightContactLensArticle", but also we could receive "leftContactLensArticle". Problem is that I always have not nil property leftArticleWithOpticalParams in model (but properties of leftArticleWithOpticalParams are nil).
Here are header of ContactLensInfo:
@interface ContactLensInfo : NSObject
@property (nonatomic, strong) NSString *modelID;
@property (nonatomic, strong) NSString *name;
@ property (nonatomic, strong) FLContactLensArticleWithOpticalParams *leftArticleWithOpticalParams;
@property (nonatomic, strong) FLContactLensArticleWithOpticalParams *rightArticleWithOpticalParams;
@property (nonatomic, strong) NSNumber *activatedForOnline;
@end

Here are how mapping occurs on root level:
+ (FEMMapping *)defaultMapping {
FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:self.class];
[mapping addAttributesFromArray:@[@"activatedForOnline", @"name"]];
[mapping addAttributesFromDictionary:@{@"modelID": @"id"}];
FEMMapping *leftArticleMapping = [FLContactLensArticleWithOpticalParams defaultMappingWithArticleKeyPath:@"leftContactLensArticle" opticalParamsKeyPath:@"leftOpticalSpecification"];
FEMRelationship *leftRS = [[FEMRelationship alloc] initWithProperty:@"leftArticleWithOpticalParams" mapping:leftArticleMapping];
[mapping addRelationship:leftRS];

FEMMapping *rightArticleMapping = [FLContactLensArticleWithOpticalParams defaultMappingWithArticleKeyPath:@"rightContactLensArticle" opticalParamsKeyPath:@"rightOpticalSpecification"];
FEMRelationship *rightRS = [[FEMRelationship alloc] initWithProperty:@"rightArticleWithOpticalParams" mapping:rightArticleMapping]; [mapping addRelationship:rightRS];
return mapping;
}

from fasteasymapping.

dimazen avatar dimazen commented on September 20, 2024

Sorry, was highly busy. It seems, I got what you're talking about.
From what I see you need to set keyPath to the relationship itself, not to the leftArticleMapping . It is a bit confusing, but the issue here is that during relationship parsing deserializer takes your relationship, sees that there is no keyPath and uses the whole object representation. Therefore it thinks that object exists, while it is not.

from fasteasymapping.

fedser avatar fedser commented on September 20, 2024

Ok, I see what you mean and your first reply in this thread was correct but I misunderstood it while. Yes, I need more like "mandatory keys" for my case, but in this case library will be more complex. Thanks!

from fasteasymapping.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.