diff --git a/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/files/model/FileEvent.scala b/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/files/model/FileEvent.scala index f3034a1fb6..4a39ace3e0 100644 --- a/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/files/model/FileEvent.scala +++ b/delta/plugins/storage/src/main/scala/ch/epfl/bluebrain/nexus/delta/plugins/storage/files/model/FileEvent.scala @@ -12,6 +12,7 @@ import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.JsonLdContext.keywords import ch.epfl.bluebrain.nexus.delta.sdk.implicits._ import ch.epfl.bluebrain.nexus.delta.plugins.storage.instances._ import ch.epfl.bluebrain.nexus.delta.plugins.storage.storages.StoragesConfig.StorageTypeConfig +import ch.epfl.bluebrain.nexus.delta.sdk.circe.JsonObjOps import ch.epfl.bluebrain.nexus.delta.sdk.jsonld.IriEncoder import ch.epfl.bluebrain.nexus.delta.sdk.model.BaseUri import ch.epfl.bluebrain.nexus.delta.sdk.model.metrics.EventMetric._ @@ -23,7 +24,7 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.Subject import ch.epfl.bluebrain.nexus.delta.sourcing.model.Tag.UserTag import ch.epfl.bluebrain.nexus.delta.sourcing.model.{EntityType, Label, ProjectRef, ResourceRef} import io.circe.generic.extras.Configuration -import io.circe.generic.extras.semiauto.{deriveConfiguredCodec, deriveConfiguredEncoder} +import io.circe.generic.extras.semiauto.{deriveConfiguredCodec, deriveConfiguredDecoder, deriveConfiguredEncoder} import io.circe.generic.semiauto.deriveEncoder import io.circe.syntax._ import io.circe.{Codec, Decoder, Encoder, Json} @@ -266,7 +267,8 @@ object FileEvent { deriveConfiguredCodec[Digest] implicit val fileAttributesCodec: Codec.AsObject[FileAttributes] = deriveConfiguredCodec[FileAttributes] - implicit val coder: Codec.AsObject[FileEvent] = deriveConfiguredCodec[FileEvent] + implicit val enc: Encoder.AsObject[FileEvent] = deriveConfiguredEncoder[FileEvent].mapJsonObject(_.dropNulls) + implicit val codec: Codec.AsObject[FileEvent] = Codec.AsObject.from(deriveConfiguredDecoder, enc) Serializer() } @@ -335,6 +337,7 @@ object FileEvent { } deriveConfiguredEncoder[FileEvent] .encodeObject(event) + .dropNulls .remove("storage") .remove("storageType") .addIfExists("_storage", storageJsonOpt) diff --git a/delta/plugins/storage/src/test/resources/files/database/file-created.json b/delta/plugins/storage/src/test/resources/files/database/file-created.json index 16f4154946..4c323ebfe8 100644 --- a/delta/plugins/storage/src/test/resources/files/database/file-created.json +++ b/delta/plugins/storage/src/test/resources/files/database/file-created.json @@ -3,7 +3,6 @@ "project" : "myorg/myproj", "storage" : "https://bluebrain.github.io/nexus/vocabulary/disk-storage?rev=1", "storageType" : "DiskStorage", - "tag" : null, "attributes" : { "origin" : "Client", "uuid" : "8049ba90-7cc6-4de5-93a1-802c04200dcc", diff --git a/delta/plugins/storage/src/test/resources/files/sse/file-created.json b/delta/plugins/storage/src/test/resources/files/sse/file-created.json index 5c8ae298dd..1ab5ab912b 100644 --- a/delta/plugins/storage/src/test/resources/files/sse/file-created.json +++ b/delta/plugins/storage/src/test/resources/files/sse/file-created.json @@ -4,7 +4,6 @@ "https://bluebrain.github.io/nexus/contexts/files.json" ], "@type": "FileCreated", - "tag": null, "_attributes": { "_bytes": 12, "_digest": { diff --git a/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/circe/package.scala b/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/circe/package.scala index 28f72441e3..c1cd50ffa3 100644 --- a/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/circe/package.scala +++ b/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/circe/package.scala @@ -3,7 +3,7 @@ package ch.epfl.bluebrain.nexus.delta.sdk import cats.Order import cats.data.NonEmptyMap import io.circe.syntax.EncoderOps -import io.circe.{Decoder, Encoder} +import io.circe.{Decoder, Encoder, JsonObject} package object circe { @@ -21,4 +21,10 @@ package object circe { } } + + implicit class JsonObjOps(j: JsonObject) { + def dropNulls: JsonObject = dropNullValues(j) + } + + def dropNullValues(j: JsonObject): JsonObject = j.filter { case (_, v) => !v.isNull } } diff --git a/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/resources/model/ResourceEvent.scala b/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/resources/model/ResourceEvent.scala index b9784a79e0..9eca75d08a 100644 --- a/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/resources/model/ResourceEvent.scala +++ b/delta/sdk/src/main/scala/ch/epfl/bluebrain/nexus/delta/sdk/resources/model/ResourceEvent.scala @@ -5,6 +5,7 @@ import ch.epfl.bluebrain.nexus.delta.rdf.Vocabulary.{contexts, nxv} import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.ContextValue import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.context.JsonLdContext.keywords import ch.epfl.bluebrain.nexus.delta.rdf.jsonld.{CompactedJsonLd, ExpandedJsonLd} +import ch.epfl.bluebrain.nexus.delta.sdk.circe.{dropNullValues, JsonObjOps} import ch.epfl.bluebrain.nexus.delta.sdk.instances._ import ch.epfl.bluebrain.nexus.delta.sdk.jsonld.IriEncoder import ch.epfl.bluebrain.nexus.delta.sdk.model.BaseUri @@ -340,7 +341,7 @@ object ResourceEvent { implicit val projectRefEncoder: Encoder[ProjectRef] = IriEncoder.jsonEncoder[ProjectRef] Encoder.encodeJsonObject.contramapObject { event => val obj = deriveConfiguredEncoder[ResourceEvent].encodeObject(event) - dropNullValues(obj) + obj.dropNulls .remove("compacted") .remove("expanded") .remove("remoteContexts") @@ -348,6 +349,4 @@ object ResourceEvent { } } } - - private def dropNullValues(j: JsonObject): JsonObject = j.filter { case (_, v) => !v.isNull } }