You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using enum as parameter with default value. Default value is always used instead of the one I passed to request.
Test case:
importorg.scalatest.{Matchers, WordSpec}
importakka.http.scaladsl.testkit.ScalatestRouteTestimportakka.http.scaladsl.server._importDirectives._importenumeratum.{Enum, EnumEntry}
sealedtraitSortOrderextendsEnumEntryobjectSortOrderextendsEnum[SortOrder] {
caseobjectAscextendsSortOrdercaseobjectDescextendsSortOrderoverridevalvalues= findValues
}
classKebsTestextendsWordSpecwithMatcherswithScalatestRouteTest {
importpl.iterators.kebs.unmarshallers._importenums._valsmallRoute=
get {
path("test_enum") {
parameter('sort.as[SortOrder] ?SortOrder.Desc) { sort =>
complete {
s"Sort was $sort"
}
}
}
}
"Kebs" should {
"work with default enum values" in {
Get("/test_enum?sort=Asc") ~> smallRoute ~> check {
responseAs[String] shouldBe "Sort was Asc"
}
}
}
}
The text was updated successfully, but these errors were encountered:
dbronecki
changed the title
Enums with default value are ommited from request
Default Enum value is always used instead of the one passed in request
May 18, 2017
Thank you for the analysis. So, as you discovered, it is because the ? method changes type of NameReceptacle (it is defined as def ?[B](default: B) = new NameDefaultReceptacle(name, default)) - so, ong story short - the Unmarshaller that is materialized is FromStringUnmarshaller[SortOrder.Desc.type] - provided by kebs for case objects. The unmarshaller for case object ignores its argument and returns constant object - which is the direct cause for the bug. Thanks @dbronecki for analysis! I fixed that in 71ad0b2 by removing case objects' unmarshallers - it doesn't look like a feature that is needed. I think that it was worth sacrificing this unneeded feature for less surprising behavior. Let me know wdyt @dbronecki !
I'm using enum as parameter with default value. Default value is always used instead of the one I passed to request.
Test case:
The text was updated successfully, but these errors were encountered: