[ANN] New, Scala reflection based lift-json extractor

32 views
Skip to first unread message

Matt Farmer

unread,
Jul 12, 2017, 9:26:24 PM7/12/17
to Lift
Good evening folks,

I wanted to let you all know that I've implemented a custom, Scala reflection based extractor for
lift-json's AST. If you're not super familiar with lift-json, extraction is the point at which we take
the json AST (JValue, et al) and turn it into a concrete Scala class (String, class of your
choosing, etc).

The motivation for implementing this extractor came out of some difficulties I run into while
working to add tuple support to lift-json. The code we currently use for extraction relies on
Java reflection and the Scala compiler library. This implementation, by contrast, uses Scala
reflection and provides a much cleaner implementation for much of the same functionality.

This is an **alpha** implementation... it doesn't yet have feature parity with the main lift-json
extractor. For example, it does not support:
  • Extracting an Array

  • Extracting using custom deserializers
... and probably some other gaps that I don't know about yet.

However! If you've got some fairly straightforward serialization/deserialization needs please
take it for a spin. It's available as a Lift module on Maven Central. You can include it in your
project by adding the following to you build file:

libraryDependencies += "net.liftmodules" %% "json-extractor-ng_3.1" % "0.1.0"

This module requires Scala 2.12.


Try it out, let me know what you think, and file issues for any bugs you find!

Cheers,
Matt

Antonio Salazar Cardozo

unread,
Jul 18, 2017, 10:48:25 AM7/18/17
to Lift
This is pretty stellar, dude. Clean, understandable code is a big win. Great work!
Antonio

Andreas Joseph Krogh

unread,
Jul 18, 2017, 12:50:00 PM7/18/17
to lif...@googlegroups.com
This is very interesting!
Are you planning to solve the issue with not being able to serialize/deserialize multiple Enumerations (because they at runtime erase to the same class)?
 
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
 

Matt Farmer

unread,
Jul 18, 2017, 1:12:49 PM7/18/17
to lif...@googlegroups.com
Hopefully eventually, yes! Though Enumerations going to change in Dotty so I don't know for how long we'll experience the feeling of victory there. =)

--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andreas Joseph Krogh

unread,
Jul 19, 2017, 4:46:40 AM7/19/17
to lif...@googlegroups.com
På tirsdag 18. juli 2017 kl. 19:12:32, skrev Matt Farmer <ma...@frmr.me>:
Hopefully eventually, yes! Though Enumerations going to change in Dotty so I don't know for how long we'll experience the feeling of victory there. =)
 
I'm not holding my breath waiting for Dotty:-)

Diego Medina

unread,
Jul 21, 2017, 10:37:00 AM7/21/17
to Lift
One issue I run once every 6 months or so with lift-json is the case where I use json.extract[ObjectId], but I don't have the right implicit in scope, so lift json goes and calls new ObjectId, which results in silent bugs because it doesn't give me the expected ObjectId, but doesn't give me an error either.

Link to old thread 

Is this any different in your library?


--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Matt Farmer

unread,
Jul 21, 2017, 10:42:00 AM7/21/17
to Lift
No, it isn't. My library actually doesn't yet support custom deserializers at all. That implementation is still forthcoming, but I'm planning to keep it in line with the existing implementation.

I will point out this is something you could fix pretty easily by providing a wrapper class around ObjectId that does more sensible things when a constructor is invoked. I'm not sure we can really expect to work around other folks's weirdness in a json library.

On Fri, Jul 21, 2017 at 10:36 AM Diego Medina <di...@fmpwizard.com> wrote:
One issue I run once every 6 months or so with lift-json is the case where I use json.extract[ObjectId], but I don't have the right implicit in scope, so lift json goes and calls new ObjectId, which results in silent bugs because it doesn't give me the expected ObjectId, but doesn't give me an error either.

Link to old thread 

Is this any different in your library?

On Wed, Jul 19, 2017 at 4:46 AM, Andreas Joseph Krogh <and...@visena.com> wrote:
På tirsdag 18. juli 2017 kl. 19:12:32, skrev Matt Farmer <ma...@frmr.me>:
Hopefully eventually, yes! Though Enumerations going to change in Dotty so I don't know for how long we'll experience the feeling of victory there. =)
 
I'm not holding my breath waiting for Dotty:-)
 
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
 

--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages