diff --git a/build.gradle b/build.gradle index 4867a81c..254949e5 100644 --- a/build.gradle +++ b/build.gradle @@ -157,7 +157,6 @@ openapiProcessor { targetDir "$buildDir/generated/sources/openapi-javax" showWarnings true openApiNullable true - // generateAliasAsModel true } } sourceSets.main.java.srcDir 'build/generated/sources/openapi' diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemEntityPatcher.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemEntityPatcher.java index 1905967b..8aa0e198 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemEntityPatcher.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemEntityPatcher.java @@ -3,14 +3,10 @@ package net.hostsharing.hsadminng.hs.booking.item; import net.hostsharing.hsadminng.hs.booking.generated.api.v1.model.HsBookingItemPatchResource; import net.hostsharing.hsadminng.mapper.EntityPatcher; import net.hostsharing.hsadminng.mapper.OptionalFromJson; -import org.apache.commons.lang3.tuple.ImmutablePair; -import java.util.HashMap; import java.util.Map; import java.util.Optional; -import static java.util.Arrays.stream; - public class HsBookingItemEntityPatcher implements EntityPatcher { private final HsBookingItemEntity entity; @@ -24,40 +20,19 @@ public class HsBookingItemEntityPatcher implements EntityPatcher entity.getResources().patch(objectToMap(resource.getResources()))); + .ifPresent(r -> entity.getResources().patch(castToKeyValueMap(resource.getResources()))); OptionalFromJson.of(resource.getValidFrom()) .ifPresent(entity::setValidFrom); OptionalFromJson.of(resource.getValidTo()) .ifPresent(entity::setValidTo); } - static Map objectToMap(final Object obj) { + @SuppressWarnings("unchecked") + static Map castToKeyValueMap(final Object obj) { if (obj instanceof Map) { - return toKeyValueMap(obj); + return (Map) obj; } - return stream(obj.getClass().getDeclaredFields()) - .map(field -> { - try { - field.setAccessible(true); - return new ImmutablePair<>(field.getName(), field.get(obj)); - } catch (final IllegalAccessException exc) { - throw new RuntimeException(exc); - } - }) - .reduce( - new HashMap<>(), - (map, pair) -> { - map.put(pair.getKey(), pair.getValue()); - return map; - }, - (map1, map2) -> { - map1.putAll(map2); - return map1; - }); + throw new ClassCastException("Map expected, but got: " + obj); } - @SuppressWarnings("unchecked") - private static Map toKeyValueMap(final Object obj) { - return (Map) obj; - } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemEntityPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemEntityPatcherUnitTest.java index dd3a59ee..9234a3ec 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemEntityPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemEntityPatcherUnitTest.java @@ -16,7 +16,7 @@ import java.util.Map; import java.util.UUID; import java.util.stream.Stream; -import static net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntityPatcher.objectToMap; +import static net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntityPatcher.castToKeyValueMap; import static net.hostsharing.hsadminng.hs.office.debitor.TestHsOfficeDebitor.TEST_DEBITOR; import static net.hostsharing.hsadminng.mapper.PatchMap.entry; import static net.hostsharing.hsadminng.mapper.PatchMap.patchMap; @@ -72,7 +72,7 @@ class HsBookingItemEntityPatcherUnitTest extends PatchUnitTestBase< final var entity = new HsBookingItemEntity(); entity.setUuid(INITIAL_BOOKING_ITEM_UUID); entity.setDebitor(TEST_DEBITOR); - entity.getResources().putAll(objectToMap(INITIAL_RESOURCES)); + entity.getResources().putAll(castToKeyValueMap(INITIAL_RESOURCES)); entity.setCaption(INITIAL_CAPTION); entity.setValidity(Range.closedInfinite(GIVEN_VALID_FROM)); return entity;