How do you deal with subclassing collection attributes in JSONModel?
Let's say I have these two endpoints with different responses of the same "product object".
domain.com/api/1.0/getProductList
domain.com/api/1.0/getProductDetails/productId
I wrote some example code below to show you my issue:
// ProductListModel
@interface ProductListModel : JSONModel
@property (nonatomic, strong) NSNumber *productId;
@property (nonatomic, strong) NSNumber *userId;
@property (nonatomic, strong) NSArray<OrderListModel> *orders;
@end
// ProductDetailModel
@interface ProductDetailModel : ProductListModel
@property (nonatomic, strong) NSURL *productImageUrl;
@property (nonatomic, strong) NSArray<OrderDetailModel> *orders;
@end
// OrderListModel
@protocol OrderListModel <NSObject>
@end
@interface OrderListModel : JSONModel
@property (nonatomic, strong) NSNumber *orderId;
@property (nonatomic, strong) NSNumber *price;
@end
// OrderDetailModel
@protocol OrderDetailModel <NSObject>
@end
@interface OrderDetailModel : OrderListModel
@property (nonatomic, strong) NSURL *orderImageUrl;
@end
The ProductDetailModel wants the same inherited attributes as ProductListModel, but it wants the orders array in the subclassed type. However this leads to a compiler warning:
Property type 'NSArray<OrderDetailModel> *' is incompatible with type
'NSArray<OrderListModel> *' inherited from 'ProductListModel'
I found this related SO post but I'd rather not monkey patch the JSONModel library.
Edit #1:
This has been discussed in the #574, and #229 github issues before but requires a "type" string to determine what class to instantiate. This requires a change on the backend API.
Is there a way to do this without changing the backend API?