diff --git a/json/src/main/java/org/eclipse/ditto/json/ImmutableJsonObjectBuilder.java b/json/src/main/java/org/eclipse/ditto/json/ImmutableJsonObjectBuilder.java index 4a9565e2f6..11c0c47fc0 100644 --- a/json/src/main/java/org/eclipse/ditto/json/ImmutableJsonObjectBuilder.java +++ b/json/src/main/java/org/eclipse/ditto/json/ImmutableJsonObjectBuilder.java @@ -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()); } }); diff --git a/json/src/test/java/org/eclipse/ditto/json/ImmutableJsonObjectBuilderTest.java b/json/src/test/java/org/eclipse/ditto/json/ImmutableJsonObjectBuilderTest.java index 731070c4f4..b79ea6439f 100644 --- a/json/src/test/java/org/eclipse/ditto/json/ImmutableJsonObjectBuilderTest.java +++ b/json/src/test/java/org/eclipse/ditto/json/ImmutableJsonObjectBuilderTest.java @@ -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); diff --git a/things/service/src/main/java/org/eclipse/ditto/things/service/persistence/serializer/ThingMongoEventAdapter.java b/things/service/src/main/java/org/eclipse/ditto/things/service/persistence/serializer/ThingMongoEventAdapter.java index a44d911e70..f5e269505f 100644 --- a/things/service/src/main/java/org/eclipse/ditto/things/service/persistence/serializer/ThingMongoEventAdapter.java +++ b/things/service/src/main/java/org/eclipse/ditto/things/service/persistence/serializer/ThingMongoEventAdapter.java @@ -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; @@ -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. @@ -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 {