Hi Jim,
Thanks for the clear questions and examples!
For the second problem, the current source version (as-yet unreleased) supports \-style access of object keys using strings, so
json.datum.wait
could instead be written as
json \ "datum" \ "wait"
which would avoid the problem with methods already defined on `AnyRef`, like `wait`, `toString`, `notify` and `equals`. Luckily there aren't many of them, but they can catch you out when you're not expecting them. All the non-dynamic methods defined on `Json` types are either symbolic, or begin with a `$` (in which case, they're only intended for internal usage) so as not to pollute the namespace.
If you're using version 1.1.0, for now, unfortunately, you'll have to use the `selectDynamic` method instead of `\`, like this:
json.datum.selectDynamic("wait")
This is basically what the dynamic accesses get translated to by the compiler.
Your first example is not something I had considered before, so it's an interesting challenge. The "obvious" answer is to define your own extractor, though this requires a lot of boilerplate. Here's an example for your Datum class, assuming that we rename `wait` to something else:
implicit val datumExtractor: Extractor[Datum, Json] =
Json.extractor[Json].map { j =>
Datum(
j.id.as[String], j.selectDynamic("wait").as[Long], ...)
}
This extractor should then take precedence over the default one, and you shouldn't get the problem with `wait`.
Another solution, as you suggested, was to rename a field. I was going to suggest that you just add the new element with `+` and remove the old with `-`. But I've just spotted that `-` doesn't exist, which is an oversight (
https://github.com/propensive/rapture-json/issues/42). That doesn't actually matter, because case class extraction will just ignore any unused fields, so you should be able to write:
val datum = (json + (_.waitVal, json.selectDynamic("wait"))).as[Datum]
and that should work.
I'm a little reluctant to either complicate the macro with rename functionality (in particular, I'd like to avoid annotations as a possible solution to this), and there doesn't seem to be a particularly clean way of providing it without introducing further confusion. But I'd be interested to hear how things go with the above workarounds.
Cheers,
Jon