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

feat: 🚀 Provide Play-JSON body encoder #114

Merged
merged 2 commits into from
Dec 9, 2021

Conversation

gaeljw
Copy link
Collaborator

@gaeljw gaeljw commented Nov 26, 2021

This PR brings supports for Play-JSON in addition to Circe as the JSON library for encoding/decoding.

I basically copy/pasted (tests included) what's inside the pact4s-circe project and adapted it to Play-JSON.

This will close #10

@jbwheatley jbwheatley merged commit 5fad42c into jbwheatley:main Dec 9, 2021
@jbwheatley
Copy link
Owner

nice 👍

@gaeljw gaeljw deleted the playjson branch December 9, 2021 17:32
)

val playJson: Seq[ModuleID] = Seq(
"com.typesafe.play" %% "play-json" % _playJson,

Choose a reason for hiding this comment

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

we should probably make this % Provided, otherwise we lock the user into a version

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This doesn't lock user in a version, they can still use another version in their codebase (direct dependency or using dependencyOverrides) as long as the version is compatible.

By the way, recent versions of sbt will let users know if they are pulling 2 incompatible (according to semver) versions.

If we put it to scope Provided and users use a version incompatible with what we expected in pact4s, it would break as well.

Copy link

@solarmosaic-kflorence solarmosaic-kflorence Dec 10, 2021

Choose a reason for hiding this comment

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

@gaeljw right -- it's just that this is what the Provided scope is for, it requires the user to include this library and include a compatible version of play JSON -- rather than including one by default which needs to be excluded if the user wants to use a different version (or being evicted if they include a version in addition to the default one). It's just cleaner, IMO, and also a pattern we already use in this library.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't see any downside of using the Compile scope: on the contrary it will let sbt highlight potential incompatibilities. I might be wrong or partial but Provided scope is more for context like Tomcat or Spark where the runtime server bring the dependencies itself. If your code needs play-json it must declare it needs it IMHO.

Anyway I'll adapt to the standards/pattern of this library if needed :)

Though it's already merged and circe module is setup the same way: https://github.com/jbwheatley/pact4s/blob/main/project/Dependencies.scala#L50

Choose a reason for hiding this comment

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

If someone is bringing this library into their project, they will already have a version of play-json defined. Since you include it in the Compile scope this means:

  • there are now potentially two versions included, one being evicted
  • they will need to remove their existing inclusion (may not be feasible depending on project setup)
  • they will need to exclude the version included by the pact4s library

I don't see any benefit to including it in Compile scope, personally. In fact, your example is the only other place where we don't include the dependency as Provided. Not a hill I'm going to die on, maybe @jbwheatley can weigh in.

Choose a reason for hiding this comment

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

PS, I don't think there really is a right answer to this, it just depends on the dependency strategy we want to take for this library. We can either include everything in Compile scope and let the users handle potential evictions/conflicts, or we can use Provided scope and force users to explicitly include a compatible version of the dependency, which I prefer simply because I think it's less complicated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I totally understand your point. I guess it's a matter of habits/taste as well. I'll be fine with any choice :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add JSON conversion support for play-json
3 participants