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

[extras-circe] Add renameFields for Codec to rename circe Json fields #336

Closed
kevin-lee opened this issue Mar 5, 2023 · 0 comments · Fixed by #338
Closed

[extras-circe] Add renameFields for Codec to rename circe Json fields #336

kevin-lee opened this issue Mar 5, 2023 · 0 comments · Fixed by #338
Assignees
Labels
task Task
Milestone

Comments

@kevin-lee
Copy link
Owner

Task

Summary

[extras-circe] Add renameFields for Codec to rename circe Json fields

Project Details

Version: 0.32.0

Description

final case class Something(a: Int, b: String, price: BigDecimal, c: Boolean)
object Something {
  import extras.circe.codecs.codec._
  implicit val somethingEncoder: Codec[Something] =
    deriveCodec[Something].renameFields(
      "a"  -> "productNumber",
      "b"  -> "name",
      "c" -> "inStock",
    )
}

val something = Something(1, "Vibranium Shield", BidDecimal(9999999), false)

Encoding:

import io.circe.syntax._
something.asJson.spaces2
{
  "id": 1,
  "name": "Vibranium Shield",
  "price": 9999999,
  "inStock": false
}

Decoding:

val json = """{
  "productNumber": 1,
  "name": "Vibranium Shield",
  "price": 9999999,
  "inStock": false
}"""

import io.circe.parser._
decode[Something](json)
// Either[Error, Something] = Right(Something(a = 1, b = "Vibranium Shield", price = 9999999, c = false))
@kevin-lee kevin-lee added the task Task label Mar 5, 2023
@kevin-lee kevin-lee added this to the milestone34 milestone Mar 5, 2023
@kevin-lee kevin-lee self-assigned this Mar 5, 2023
kevin-lee added a commit that referenced this issue Mar 5, 2023
kevin-lee added a commit that referenced this issue Mar 6, 2023
kevin-lee added a commit that referenced this issue Mar 6, 2023
Close #336 - [`extras-circe`] Add `renameFields` for `Codec` to rename circe `Json` fields
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
task Task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant