Skip to content

feat(lift-json)!: Prepare for scala 3 with type extractor#2030

Merged
farmdawgnation merged 5 commits intolift-4.0from
msf/lift-json-scala3
Aug 1, 2025
Merged

feat(lift-json)!: Prepare for scala 3 with type extractor#2030
farmdawgnation merged 5 commits intolift-4.0from
msf/lift-json-scala3

Conversation

@farmdawgnation
Copy link
Member

@farmdawgnation farmdawgnation commented Jul 21, 2025

Provide for a TypeExtractor interface to assist with the migration of lift-json to Scala 3. In particular:

  • Wrap the existing Manifest driven implementation in the TypeExtractor
  • Provide implicit conversions for Manifest=>TypeExtractor that work in most cases.
    • I observed one instance where the compiler didn't seem to derive this as I expected. This could be representative of a wider problem using the conversion that ultimately annoys folks.

I took this approach after evaluating how json4s has decided to support Scala 3. By my understanding this was done with the approach of augmenting reflection capabilities. I also realized there's an open bug json4s/json4s#431 (opened by me!) which doesn't seem to have been fixed yet so I'm not eager to try to dig into their reflection implementation to try and fix that and then migrate over.

Going to consider this a breaking change, even though we're going to make the attempt to smooth it over with an implicit conversion.

Earlier versions of lift-json depended heavily on the old scala Manifest
class that has been removed in Scala 3. The plan is to replace with with
metaprogramming in Scala 3, but to support that we first have to
encapsulate the existing Manifest logic into a separate class. This is
the starting point toward doing that.
@farmdawgnation farmdawgnation changed the title feat(lift-json): Prepare for scala 3 with type extractor feat(lift-json)!: Prepare for scala 3 with type extractor Jul 23, 2025
@farmdawgnation farmdawgnation requested review from Copilot and dpp July 23, 2025 11:25
@farmdawgnation
Copy link
Member Author

@dpp Keep me honest, but I think this approach is viable with minimal disruption to the API. :)

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces a TypeExtractor interface to facilitate the migration of lift-json from Scala 2.13 to Scala 3. The PR replaces direct usage of Manifest with the new TypeExtractor abstraction while maintaining backward compatibility through implicit conversions.

Key changes:

  • Introduces TypeExtractor trait as an abstraction over type information extraction
  • Updates all JSON extraction methods to use TypeExtractor instead of Manifest
  • Provides implicit conversion from Manifest to TypeExtractor for compatibility

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
core/json/src/main/scala/net/liftweb/json/Extraction.scala Introduces the TypeExtractor trait and updates extraction methods to use it
core/json/src/main/scala/net/liftweb/json/JsonAST.scala Updates extract, extractOpt, and extractOrElse methods to use TypeExtractor
core/json/src/main/scala/net/liftweb/json/Serialization.scala Updates read methods to use TypeExtractor and removes Manifest import
core/json/src/main/scala/net/liftweb/json/Formats.scala Updates field serializer methods to use TypeExtractor
core/json/src/main/scala/net/liftweb/json/FieldSerializer.scala Updates type constraint to use TypeExtractor
web/webkit/src/main/scala/net/liftweb/http/LiftSession.scala Manually applies conversion where implicit conversion failed
Comments suppressed due to low confidence (1)

core/json/src/main/scala/net/liftweb/json/Extraction.scala:95

  • [nitpick] The function name convertTypeExtractorToClasses is verbose and unclear. Consider renaming to extractClasses or getAllClasses to better reflect its purpose of extracting all classes from a TypeExtractor hierarchy.
    def convertTypeExtractorToClasses(te: TypeExtractor[_]): List[Class[_]] = {

Copy link
Member

@dpp dpp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My Scala 3 is weak, bit this generally looks okay.

But... should we consider dropping Lift JSON for Scala 3/Lift 5 in favor of https://github.com/json4s/json4s

@farmdawgnation
Copy link
Member Author

@dpp Yeah, agree on the long term strategy being leaning on something else rather than continuing to maintain our own. I'm still concerned about the polymorphism issue. :/

@farmdawgnation farmdawgnation marked this pull request as ready for review July 25, 2025 01:30
@farmdawgnation farmdawgnation merged commit f79d30e into lift-4.0 Aug 1, 2025
6 checks passed
@farmdawgnation farmdawgnation deleted the msf/lift-json-scala3 branch August 1, 2025 02:41
@github-project-automation github-project-automation bot moved this to In progress in Lift 4.0 Aug 21, 2025
@farmdawgnation farmdawgnation moved this from In progress to Done in Lift 4.0 Aug 21, 2025
@farmdawgnation farmdawgnation restored the msf/lift-json-scala3 branch September 21, 2025 02:22
@bishabosha
Copy link

If you want to preserve compat with the Manifest in Scala 3, i could suggest porting the Scala 3 compilers implementation to quotes/splices: https://github.com/scala/scala3/blob/577721f395350461499c3a71a7a0c934aa09109c/compiler/src/dotty/tools/dotc/typer/Synthesizer.scala#L680-L788

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants