-
Notifications
You must be signed in to change notification settings - Fork 190
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
Supports snakecase. #268
base: master
Are you sure you want to change the base?
Supports snakecase. #268
Conversation
8c601fc
to
a543a40
Compare
Hope this will be merged soon! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @jkugiya. The feature looks good to me. I wonder if we shouldn't use the simple implementation based on regexs.
trait SnakeCaseJsonSupport extends DefaultJsonProtocol { | ||
|
||
override protected def extractFieldNames(classTag: ClassTag[_]): Array[String] = { | ||
def snakify(name: String) = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should also just use the regex here? Performance shouldn't be an issue as the formats are usually only evaluated once per type.
val sampleFields2 = SampleFields2().toJson.asJsObject | ||
// Then | ||
val fields1 = sampleFields1.fields | ||
fields1.contains(snakify("HelloWorld")) mustEqual true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good that snakify
is a different implementation here in the test, but I would prefer if the test case expectations would be spelled out.
val sampleFields2 = SampleFields2().toJson.asJsObject | ||
// Then | ||
val fields1 = sampleFields1.fields | ||
fields1.contains(snakify("HelloWorld")) mustEqual true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good that snakify
is a different implementation here in the test, but I would prefer if the test case expectations would be spelled out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E.g. like this:
fields1.contains(snakify("HelloWorld")) mustEqual true | |
fields1 must haveKey("hello_world") |
@plokhotnyuk I also tried your implementation. But some of the behavior is unexpected for me in some corner case. ex)
It is difficult to judge which is better because there aren't standard specification for this conversion, as far as I know. |
Close #170