-
Notifications
You must be signed in to change notification settings - Fork 10
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
Adds JNumber conversions #41
Conversation
This implementation is loosely based on that of Circe.
Codecov Report
@@ Coverage Diff @@
## master #41 +/- ##
===========================================
- Coverage 44.68% 26.07% -18.62%
===========================================
Files 5 5
Lines 687 1097 +410
Branches 133 170 +37
===========================================
- Hits 307 286 -21
- Misses 380 811 +431
Continue to review full report at Codecov.
|
def unapply(value: JNumber): Option[String] = Option(value.stringValue) | ||
|
||
private[ast] def jnumberEquals(value: JNumber, obj: Any): Boolean = | ||
(value, obj) match { |
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.
Seeing as jnumberEquals
might be hot in certain kinds of applications: Could this be expressed in an allocation-free manner (possibly sacrificing a bit of conciseness)?
IMHO representing JSON numbers via an ADT like this is the way to go. |
@sirthias I suppose if the internals change then you are not breaking it for end users? |
IMHO this whole effort is about not changing anything, ever. This is not a library that receives new features or other upgrades over time. That's why simplicity and clarity is quite important in my view. Any special construct, hidden fields, non-case-classes or other "tricks" should be extremely well justified. |
Completely agree, which is why I am being very careful about a release. Will need @eed3si9n , and possibly @travisbrown to clarify why they are private |
Unlike Json4s's AST where you get either For example, suppose I am getting "Twitter fave count", and I assume the number can be represented as |
I agree with the general idea, but we should relax this to keeping strict binary compatibility of the exposed classes. Other goals are correctness, user-friendliness, and performance. Hiding often allows us to do performance tricks without compromising on the usability of the surface API. |
* @author Matthew de Detrich | ||
*/ | ||
// Due to a restriction in Scala 2.10, we cant override/replace the default apply method | ||
// generated by the compiler even when the constructor itself is marked private |
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.
Since I can compile my JNumber in 2.10, 2.10 duplication is dropped.
@eed3si9n Thanks, I will have a look at this today/tomorrow |
Yes, I fully agree. However, in my view this project is a bit different from ordinary libraries as it provides almost only structure and very little logic (at least I would consider this a goal). My concern with hiding the internal ADT structure is that there will definitely be people that will want to access the underlying inner structure, if only to perf-optimize certain cases on their layer. If we come up with right structure anyone who doesn't care about details can simply rely on the |
Regarding #38 , this was an attempt to provide performant JNumber conversions without altering the current API design too much, hence why the JNumber constructor was largely unchanged and we are using a bitflag |
Closing this in favor of #42 |
Ref #38
This implementation is loosely based on that of Circe.
JNumber
is internally subdivided into package private seven datatypesJStringDecimal
,JBigDecimal
,JBigInt
,JLong
,JInt
,JDouble
, andJFloat
corresponding to the input values passed intoJNumber.apply(...)
. This allows performant roundtrip back to the original number types, if needed.Note that the parser implementer now has an option of constructing
JStringDecimal
viaJNumber(value: String)
or doing the number parsing upfront.