We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Error message that enumeratum produces could be enriched with list of valid enum values.
For example if there is enum
sealed trait Operand extends EnumEntry with Hyphencase with Lowercase object Operand extends enumeratum.Enum[Operand] with PlayJsonEnum[Operand] { val values = findValues case object Equals extends Operand case object Gt extends Operand case object GtEq extends Operand case object Lt extends Operand case object LtEq extends Operand }
and some case class
case class Foo(operand: Operand) object Foo { implicit val format: Format[Foo] = Json.format }
Then attempt to parse the string
test("parse json string into case class with enum") { val jsonString = "{\"operand\":\"unknown\"}" Json.parse(jsonString).as[Foo] }
will print error
JsResultException(errors:List((/operand,List(JsonValidationError(List(error.expected.validenumvalue),WrappedArray())))))
But what if we will extend EnumFormats and let it print error with details like:
JsResultException(errors:List((/operand,List(JsonValidationError(List(error.expected.validenumvalue),WrappedArray(valid enum values are: (equals, gt, gt-eq, lt, lt-eq, not-equals, in, not-in), but provided: unknown))))))
with change like this at EnumFormats:140:
private def readsKeyAndExtracts[A <: EnumEntry]( @deprecatedName(Symbol("enum")) e: Enum[A] )(extract: String => Option[A]): KeyReads[A] = new KeyReads[A] { def readKey(s: String): JsResult[A] = extract(s) match { case Some(obj) => JsSuccess(obj) case None => JsError( JsonValidationError( "error.expected.validenumvalue", s"valid enum values are: (${e.values.map(_.entryName).mkString(", ")}), but provided: $s" ) ) } }
It can be disabled by default, configurable by some flag in trait PlayJsonEnum.
Does it make sense to implement?
The text was updated successfully, but these errors were encountered:
I think this sounds like a nice enhancement.
Sorry, something went wrong.
You should fork and push the branch to your fork then send a PR here.
@lloydmeta PR at #411
No branches or pull requests
Error message that enumeratum produces could be enriched with list of valid enum values.
For example if there is enum
and some case class
Then attempt to parse the string
will print error
But what if we will extend EnumFormats and let it print error with details like:
with change like this at EnumFormats:140:
It can be disabled by default, configurable by some flag in trait PlayJsonEnum.
Does it make sense to implement?
The text was updated successfully, but these errors were encountered: