Comments (4)
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.
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.
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.
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)
- Data Fault HOT 3
- Relation Object added but root object store temporary not permnent HOT 1
- Load Data Takes Time
- Remove Root Object
- Mapping One object at a time HOT 1
- Crash using relationship binding by PK HOT 9
- Never ending recursion HOT 1
- What is this? When I install the pod HOT 2
- Primary key not required HOT 4
- is FastEasyMapping ready for swift 4? HOT 3
- IN Operator with no sorting
- Synchronise local and server id HOT 25
- Swift Package Manager Support HOT 1
- getting error in mapping HOT 2
- Getting crash App While Mapping
- Can not map attribute from string to Double HOT 5
- How to map a data model where the key in json is not fixed ? HOT 1
- App is crashing while trying to save data in database HOT 1
- How to map double value in Swift HOT 2
- Getting value nill after mapping
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fasteasymapping.