From 06a8b2936df616ef8a6859cd1e19494eb5323b1b Mon Sep 17 00:00:00 2001 From: Cato Olsen Date: Thu, 11 Jul 2024 15:11:21 +0200 Subject: [PATCH] Rettet NPE hvis manglende type naturalytelse. --- .../mapper/InntektsmeldingMappingStrategy.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/inntektsmelding/mapper/InntektsmeldingMappingStrategy.java b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/inntektsmelding/mapper/InntektsmeldingMappingStrategy.java index 966d44a2579..e60fb258c34 100644 --- a/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/inntektsmelding/mapper/InntektsmeldingMappingStrategy.java +++ b/apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/inntektsmelding/mapper/InntektsmeldingMappingStrategy.java @@ -26,6 +26,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.Optional; import static java.util.Objects.isNull; import static java.util.Objects.nonNull; @@ -114,7 +115,9 @@ public void mapAtoB(RsInntektsmelding.Inntektsmelding rsInntektsmelding, .stream() .map(ytelse -> { var mapped = mapperFacade.map(ytelse, RsNaturalytelseDetaljer.class); - mapped.setNaturalytelseType(ytelse.getNaturalytelseType().getJsonValue()); // Don't use the string representation of the enum; use the JSON value corresponding to the enum. + Optional + .ofNullable(ytelse.getNaturalytelseType()) + .ifPresent(type -> mapped.setNaturalytelseType(type.getJsonValue())); return mapped; }) .toList() @@ -125,7 +128,9 @@ public void mapAtoB(RsInntektsmelding.Inntektsmelding rsInntektsmelding, .stream() .map(ytelse -> { var mapped = mapperFacade.map(ytelse, RsNaturalytelseDetaljer.class); - mapped.setNaturalytelseType(ytelse.getNaturalytelseType().getJsonValue()); // Don't use the string representation of the enum; use the JSON value corresponding to the enum. + Optional + .ofNullable(ytelse.getNaturalytelseType()) + .ifPresent(type -> mapped.setNaturalytelseType(type.getJsonValue())); return mapped; }) .toList()