Skip to content

Commit

Permalink
Merge pull request #1798 from eclipse-ditto/bugfix/json-object-builde…
Browse files Browse the repository at this point in the history
…r-remove

fix that JsonObjectBuilder.remove removes to much in certain cases
  • Loading branch information
thjaeckle authored Nov 8, 2023
2 parents d008959 + 4697680 commit 93b73de
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private ImmutableJsonObjectBuilder remove(final JsonPointer pointer) {
rootObject = rootObject.remove(nextPointerLevel);
set(JsonFactory.newField(jsonField.getKey(), rootObject,
jsonField.getDefinition().orElse(null)));
} else {
} else if (nextPointerLevel.isEmpty()) {
fields.remove(jsonField.getKeyName());
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ public void removeWithJsonPointerWorksAsExpected() {
.set(robert)
.set(cersei)
.remove(JsonFactory.newPointer(fooKey, bazKey))
.remove(JsonFactory.newPointer(robert.getKey(), JsonKey.of("non-existing")))
.build();

assertThat(actualJsonObject).isEqualTo(expectedJsonObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.eclipse.ditto.things.service.persistence.serializer;

import org.apache.pekko.actor.ExtendedActorSystem;
import org.eclipse.ditto.base.model.signals.events.Event;
import org.eclipse.ditto.base.model.signals.events.GlobalEventRegistry;
import org.eclipse.ditto.base.service.config.DittoServiceConfig;
Expand All @@ -25,8 +26,6 @@
import org.eclipse.ditto.things.model.signals.events.ThingMerged;
import org.eclipse.ditto.things.service.common.config.DefaultThingConfig;

import org.apache.pekko.actor.ExtendedActorSystem;

/**
* EventAdapter for {@link Event}s persisted into pekko-persistence event-journal. Converts Event to MongoDB
* BSON objects and vice versa.
Expand All @@ -48,7 +47,7 @@ public ThingMongoEventAdapter(final ExtendedActorSystem system) {

@Override
protected JsonObjectBuilder performToJournalMigration(final Event<?> event, final JsonObject jsonObject) {
if (event instanceof ThingMerged) {
if (event instanceof ThingMerged thingMerged && thingMerged.getResourcePath().isEmpty()) {
return super.performToJournalMigration(event, jsonObject)
.remove(POLICY_IN_THING_MERGED_VALUE_PAYLOAD); // remove the policy entries from thing merged payload
} else {
Expand Down

0 comments on commit 93b73de

Please sign in to comment.