matthewcheok / Realm-JSON

A concise Mantle-like way of working with Realm and JSON.
MIT License
661 stars 129 forks source link

Custom RLMObject to JSON mapping (symmetric method to +preprocessedJSON needed) #92

Open pankkor opened 8 years ago

pankkor commented 8 years ago

If I want to make any complicated preprocessing on JSON before mapping JSON to RLMObject I can use +preprocessedJSON:, but there is no way for opposite postprocessing of RLMObject to JSON if I want to get the same JSON back from RLMObject.

One way I wanted to achieve that is by overriding -JSONDictionary but it is implemented this way: - (NSDictionary *)JSONDictionary { return [self mc_createJSONDictionary]; } and everywhere in the implementation -mc_createJSONDictionary is called. So suddenly to achieve what I want I need to override -mc_createJSONDictionary and mess with guts of implementation because -mc_createJSONDictionary is private.

  1. Why can't -JSONDictionary be called directly in the implementation?
  2. Do you have any plans to introduce a symmetric call to +preprocessedJSON:?
  3. Are there any other ways I can achieve desired behaviour?
viktorasl commented 8 years ago

JSONOutboundMappingDictionary method works fine, just make readonly property with all needed preprocessed data and map it. Some time ago I've made a PR for preprocessing of each object separately #63.