From d01d9383e2b313fdc71e78d5a829db557fe3aa60 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Mon, 6 Dec 2021 21:43:06 +0100 Subject: [PATCH] #377 - Provide proper fallback for potentially missing ConversionService in JpaEntityConverter. --- .../salespointframework/support/JpaEntityConverter.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/salespointframework/support/JpaEntityConverter.java b/src/main/java/org/salespointframework/support/JpaEntityConverter.java index 41a1d12d..da088a21 100644 --- a/src/main/java/org/salespointframework/support/JpaEntityConverter.java +++ b/src/main/java/org/salespointframework/support/JpaEntityConverter.java @@ -24,11 +24,12 @@ import javax.persistence.metamodel.EntityType; import org.jmolecules.spring.PrimitivesToIdentifierConverter; -import org.springframework.beans.factory.ObjectFactory; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.ConditionalGenericConverter; import org.springframework.core.convert.converter.Converter; +import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.stereotype.Component; import org.springframework.util.Assert; @@ -50,13 +51,14 @@ class JpaEntityConverter implements ConditionalGenericConverter { * @param em must not be {@literal null}. * @param conversionService must not be {@literal null}. */ - public JpaEntityConverter(EntityManager em, ObjectFactory conversionService) { + public JpaEntityConverter(EntityManager em, ObjectProvider conversionService) { Assert.notNull(conversionService, "EntityManager must not be null!"); Assert.notNull(conversionService, "ConversionService must not be null!"); this.em = em; - this.identifierConverter = new PrimitivesToIdentifierConverter(() -> conversionService.getObject()); + this.identifierConverter = new PrimitivesToIdentifierConverter( + () -> conversionService.getIfAvailable(DefaultConversionService::new)); } /*