Skip to content

Add support to customize nested key delimiter - #629

Merged
tristanhimmelman merged 5 commits into
tristanhimmelman:masterfrom
devxoul:map-nested-key-delimiter
Oct 22, 2016
Merged

tristanhimmelman merged 5 commits into
tristanhimmelman:masterfrom
devxoul:map-nested-key-delimiter

Conversation

@devxoul

@devxoul devxoul commented Oct 15, 2016 •

Copy link
Copy Markdown
Contributor

Summary

This PR makes it available to use custom nested key delimiter in mapping.

Background

Imagine that we have a JSON dictionary which has nested-dot-containing keys:

{
  "kr.xoul.user": {
    "kr.xoul.name": "Suyeol Jeon",
    "kr.xoul.username": "devxoul"
  }
}

In this case, mapping function would not work properly.

func mapping(map: Map) {
  // this will parse the key as ["kr"]["xoul"]["user"]["kr"]["xoul"]["name"]
  name <- map["kr.xoul.user.kr.xoul.name"]
}

Improvement

Adding delimiter parameter to map subscript.

func mapping(map: Map) {
  // this will parse the key as ["kr.xoul.user"]["kr.xoul.name"]
  name <- map["kr.xoul.user->kr.xoul.name", delimiter: "->"]
}

Notes

  • This PR also contains nested key support in ImmutableMappable. (will it better separating to another PR?)

Related Issues

@devxoul
devxoul force-pushed the map-nested-key-delimiter branch from e278f8e to c21bf08 Compare October 15, 2016 15:30
@tristanhimmelman
tristanhimmelman merged commit 4553dff into tristanhimmelman:master Oct 22, 2016
@devxoul
devxoul deleted the map-nested-key-delimiter branch October 22, 2016 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants