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

JSON Reads max and min combinators should work on any Numeric #1363

Merged
merged 2 commits into from Jul 26, 2013

Conversation

@mariussoutier
Copy link
Contributor

mariussoutier commented Jul 19, 2013

The Reads.min and Reads.max combinators in play-json currently only work on Int, but there's no reason it shouldn't work any any Numeric.

@cloudbees-pull-request-builder
Copy link

cloudbees-pull-request-builder commented Jul 19, 2013

play2-master-PRs #392 SUCCESS
This pull request looks good

def min(m: Int)(implicit reads: Reads[Int]) =
filterNot[Int](ValidationError("error.min", m))(_ < m)(reads)
/**
* Defines a minimum size for a numeric Reads. Combine with `max` using `or`, e.g.

This comment has been minimized.

@mandubian

mandubian Jul 19, 2013 Contributor

Maybe not using the word "size", it's more about the value, isn't it?

This comment has been minimized.

@mariussoutier

mariussoutier Jul 19, 2013 Author Contributor

Yes you're right, fixed it.

This comment has been minimized.

@mandubian

mandubian Jul 19, 2013 Contributor

no you can commit on your branch and the PR is updated!

On Fri, Jul 19, 2013 at 3:10 PM, Marius Soutier notifications@github.comwrote:

In
framework/src/play-json/src/main/scala/play/api/libs/json/JsConstraints.scala:

@@ -112,11 +112,19 @@ trait ConstraintReads {
def seq[A](implicit reads: Reads[A]): Reads[Seq[A]] = Reads.traversableReads[Seq, A]
def map[A](implicit reads: Reads[A]): Reads[collection.immutable.Map[String, A]] = Reads.mapReads[A]

  • def min(m: Int)(implicit reads: Reads[Int]) =
  • filterNot[Int](ValidationError%28"error.min", m%29)(_ < m)(reads)
  • /**
  • * Defines a minimum size for a numeric Reads. Combine with max using or, e.g.

Yes you're right... I guess I have to close this PR and submit a new one?


Reply to this email directly or view it on GitHubhttps://github.com//pull/1363/files#r5291461
.

This comment has been minimized.

@mariussoutier

mariussoutier Jul 19, 2013 Author Contributor

Thanks, see below. value was just the word I was looking for but then I resorted to size.

def max(m: Int)(implicit reads: Reads[Int]) =
filterNot[Int](ValidationError("error.max", m))(_ > m)(reads)
/**
* Defines a maximum size for a numeric Reads. Combine with `min` using `or`, e.g.

This comment has been minimized.

@mandubian

mandubian Jul 19, 2013 Contributor

Idem, maybe not using the word "size", it's more about the value, isn't it?

@mandubian
Copy link
Contributor

mandubian commented Jul 19, 2013

Seems OK ;)

@cloudbees-pull-request-builder
Copy link

cloudbees-pull-request-builder commented Jul 19, 2013

play2-master-PRs #393 SUCCESS
This pull request looks good

jroper added a commit that referenced this pull request Jul 26, 2013
JSON Reads max and min combinators should work on any Numeric
@jroper jroper merged commit a7d8fed into playframework:master Jul 26, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.