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

Special case Option intermediary type in extraction. #1717

Merged
merged 3 commits into from
Sep 26, 2015

Conversation

farmdawgnation
Copy link
Member

This PR resolves a long-standing bug where trying to execute extraction when Option was an intermediary type on a List would cause fireworks and explosions. So, for example if you tried something like the following:

val json = JsonParser.parse("""["one", "two", null]""")
json.extract[List[Option[String]]]

You would get explosions and fireworks because lift-json would try to match up what you've provided to the constructor for Option. We now special case Option as a type of collection in the generation of the Meta ADT, and handle that case when constructing the concrete instance.

I'm not quite familiar enough with this code to know if this is a kludge or a clever hack. Would love some 👀 from @jonifreeman (if you have time). Either way, I humbly submit this for review.

closes #1071

This essentially treats Option as a type of collection, which it is in a
way, and special-cases the handling of it so that invoking something
like `extract[List[Option[String]]]` will work as the user expects.
@farmdawgnation farmdawgnation added this to the 3.0-M7 milestone Aug 29, 2015
@@ -59,6 +59,11 @@ object ExtractionBugs extends Specification {
json.extract[Response] mustEqual Response(List(Map("one" -> 1, "two" -> 2)))
}

"Extracting List[Option[String]]" in {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phrasing here seems wrong (“Extraction should handle…” seems to be the trend above).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah.

@Shadowfiend
Copy link
Member

Looks cool!

farmdawgnation added a commit that referenced this pull request Sep 26, 2015
We now special case Option as a type of collection in the generation of the Meta ADT, and handle that case when constructing an Option[_] when invoking extract[...].
@farmdawgnation farmdawgnation merged commit fc361bc into master Sep 26, 2015
@farmdawgnation farmdawgnation deleted the msf_issue_1071 branch September 26, 2015 19:03
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.

lift-json flattens option types unexpectedly
2 participants