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

Add ninny-circe-compat #69

Merged
merged 2 commits into from
Dec 9, 2024

Conversation

romanchelsea
Copy link
Contributor

No description provided.

Comment on lines 50 to 52
val objekt = ex1json.to[Example1]
objekt match {
case Failure(e: DecodingFailure) => println(e.printStackTrace())
}
objekt shouldEqual ex1
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not passing. I'm still trying to figure out. @nrktkt

Copy link
Owner

Choose a reason for hiding this comment

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

objekt is a Try and ex1 is an Example1. so the comparison fails

Suggested change
val objekt = ex1json.to[Example1]
objekt match {
case Failure(e: DecodingFailure) => println(e.printStackTrace())
}
objekt shouldEqual ex1
}
val objekt = ex1json.to[Example1]
objekt match {
case Failure(e: DecodingFailure) => println(e.printStackTrace())
}
objekt.success.value shouldEqual ex1
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the Try is a Failure, i was trying to print the stacktrace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It turns out that NinnyToCirce and CirceToNinny put toegher, is breaking Circe itself's decoding functionality,

i.e. a Circe json object's Decoder is implicitly converted to Ninny's FromJson, then implicitly converted to Decoder, over and over.

So I think it would be better to separate CirceToNinny and NinnyToCirce

E.g.

import CirceCompat._

case class Person(name: String, age: Int)
object Person {
  implicit val encoder = deriveEncoder[Person]
  implicit val decoder = deriveDecoder[Person]
}

val json = Person("alice", 30).asJson

// Decoder[Person] is implicitly converted to FromJson[Person] by CirceCompat
// then FromJson is converted to Decoder, so on so forth
json.to[Person]

@nrktkt nrktkt self-requested a review December 3, 2024 19:13
@romanchelsea romanchelsea force-pushed the xwang/add-ninny-circe-compat branch from d9e61e3 to a9422a6 Compare December 4, 2024 11:31
with OptionValues
with TryValues {

case class Example1(foo: String, bar: Seq[Int])
Copy link
Owner

Choose a reason for hiding this comment

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

maybe just add a nested object to these examples and then I think it looks good

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a nested Person

@nrktkt nrktkt merged commit ea439a9 into nrktkt:master Dec 9, 2024
1 check passed
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.

2 participants