Skip to content

Commit

Permalink
Merge pull request #339 from Kevin-Lee/prepare-to-release
Browse files Browse the repository at this point in the history
extras v0.33.0
  • Loading branch information
kevin-lee authored Mar 6, 2023
2 parents 9af8448 + 4749252 commit b22ca75
Showing 1 changed file with 118 additions and 0 deletions.
118 changes: 118 additions & 0 deletions changelogs/0.33.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
## [0.33.0](https://github.com/Kevin-Lee/extras/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aclosed+-label%3Ainvalid+milestone%3Amilestone34) - 2023-03-06

## New Features

* [`extras-circe`] Add `renameFields` for `Encoder` to rename circe `Json` fields (#331)
```scala
final case class Something(a: Int, b: String, price: BigDecimal, c: Boolean)
object Something {
import extras.circe.codecs.encoder._
implicit val somethingEncoder: Encoder[Something] =
deriveEncoder[Something].renameFields(
"a" -> "productNumber",
"b" -> "name",
"c" -> "inStock",
)
}

import io.circe.syntax._
Something(1, "Vibranium Shield", BidDecimal(9999999), false).asJson.spaces2
```
```json
{
"id": 1,
"name": "Vibranium Shield",
"price": 9999999,
"inStock": false
}
```
* [`extras-circe`] `renameFields` for `Encoder` should fail encoding when new name conflicts with the existing name (#335)
```scala
final case class Something(n: Int, s: String, name: String)
object Something {

import extras.circe.codecs.encoder._

implicit val somethingEncoder: Encoder[Something] =
deriveEncoder[Something].renameFields(
"n" -> "productNumber",
"s" -> "name", // Something already has a field named "name"
)
}

io.circe.syntax._
Something(1, "some name", "another name").asJson
// This fails with extras.circe.codecs.encoder.NamingConflictError
```

* [`extras-circe`] Add `renameFields` for `Decoder` to rename circe `Json` fields (#333)
```scala
final case class Something(a: Int, b: String, price: BigDecimal, c: Boolean)
object Something {
import extras.circe.codecs.decoder._

implicit val somethingDecoder: Decoder[Something] =
deriveDecoder[Something].renameFields(
"a" -> "productNumber",
"b" -> "name",
"c" -> "inStock",
)
}
```
```scala
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))
```

* [`extras-circe`] Add `renameFields` for `Codec` to rename circe `Json` fields (#336)
```scala
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:
```scala
import io.circe.syntax._
something.asJson.spaces2
```
```json
{
"id": 1,
"name": "Vibranium Shield",
"price": 9999999,
"inStock": false
}
```
Decoding:
```scala
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))
```

## Improvement
* Optimize `StubToolsCats` and `StubToolsFx` (#329)

0 comments on commit b22ca75

Please sign in to comment.