Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utility method to turn objects into dictionaries with custom keys #957

Conversation

hprange
Copy link
Contributor

@hprange hprange commented Aug 6, 2021

The ERXDictionaryUtilities.dictionaryFromObjectWithKeyMappings creates a dictionary from an object according to the given key mappings, skipping null values.

Usage:

NSDictionary<String, Object> data = dictionaryFromObjectWithKeyMappings(eo, NSDictionary.of("key1", EO.ATTRIBUTE1, "key2", EO.ATTRIBUTE2);

Result:

{
    "key1" = "valueForAttribute1";
    "key2" = "valueForAttribute2";
}

The `ERXDictionaryUtilities.dictionaryFromObjectWithKeyMappings` creates a dictionary from an object according to the given key mappings, skipping `null` values.

Usage:

```
NSDictionary<String, Object> data = dictionaryFromObjectWithKeyMappings(eo, NSDictionary.of("key1", EO.ATTRIBUTE1, "key2", EO.ATTRIBUTE2);
```

Result:

```
{
    "key1" = "valueForAttribute1";
    "key2" = "valueForAttribute2";
}
```
@hprange hprange added the Wonder7 label Aug 6, 2021
@darkv darkv merged commit d38e9c0 into wocommunity:master Aug 6, 2021
@hprange hprange deleted the feature/dictionaryFromObjectWithKeyMappings branch August 6, 2021 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants