Skip to content

Commit

Permalink
Remove null attributes from response
Browse files Browse the repository at this point in the history
  • Loading branch information
Elmacioro committed Jan 2, 2025
1 parent 0997f19 commit 4e7a73a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,19 @@ object ScenarioWithDetails {

import io.circe.generic.semiauto._

// TODO: We remove null values from json to make response payload lighter.
// The target solution would be to introduce pagination to the /api/processes endpoint.
implicit val encoder: Encoder[ScenarioWithDetails] =
deriveEncoder[ScenarioWithDetails]
.contramap[ScenarioWithDetails](_.copy(processId = None))
deepDropNulls(
deriveEncoder[ScenarioWithDetails]
.contramap[ScenarioWithDetails](_.copy(processId = None))
)

implicit val decoder: Decoder[ScenarioWithDetails] =
deriveDecoder[ScenarioWithDetails]

private def deepDropNulls[A](encoder: Encoder[A]): Encoder[A] = encoder.mapJson(_.deepDropNullValues)

}

// This class is to enforce consistency of fields between CreateScenarioCommand and ScenarioWithDetails.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class ProcessesResourcesSpec
}

test("/api/processes should return lighter details without ProcessAction's additional fields") {
createDeployedWithCustomActionScenario(processName, category = Category1)
createDeployedScenario(processName, category = Category1)
Get(s"/api/processes") ~> withReaderUser() ~> applicationRoute ~> check {
status shouldEqual StatusCodes.OK
val loadedProcess = responseAs[List[ScenarioWithDetails]]
Expand Down
2 changes: 1 addition & 1 deletion docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
this fixes issue with unexpected low scale when performing division on BigDecimals which were created in such conversion.
* [#7368](https://github.com/TouK/nussknacker/pull/7368) Component rename: `periodic` to `sample-generator`
* [#7379](https://github.com/TouK/nussknacker/pull/7379) Removed CustomAction mechanism.
* [#7354](https://github.com/TouK/nussknacker/pull/7354) Reduce response payload size when fetching scenarios for scenarios tab by removing unused fields.
* [#7354](https://github.com/TouK/nussknacker/pull/7354) Reduce response payload size when fetching scenarios for scenarios tab by removing unused fields and `null` attributes.

## 1.18

Expand Down

0 comments on commit 4e7a73a

Please sign in to comment.