From 65d4d71895629dc839761c59a5f22be153c5269f Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Wed, 24 Feb 2021 17:58:39 +0100 Subject: [PATCH] Support for jMolecules Identifier types. We now properly handle jMolecules Identifier instances by integration with the corresponding Converter implementations provided by the jmolecules-spring integrations library. Fixes GH-1982. --- spring-data-rest-webmvc/pom.xml | 7 + .../webmvc/config/JMoleculesConfigurer.java | 163 ++++++++++++++++++ .../config/RestControllerImportSelector.java | 9 +- 3 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/JMoleculesConfigurer.java diff --git a/spring-data-rest-webmvc/pom.xml b/spring-data-rest-webmvc/pom.xml index da4c7f128..42ef27ddf 100644 --- a/spring-data-rest-webmvc/pom.xml +++ b/spring-data-rest-webmvc/pom.xml @@ -35,6 +35,13 @@ org.springframework spring-webmvc + + + org.jmolecules.integrations + jmolecules-spring + ${jmolecules-integration} + true + javax.servlet diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/JMoleculesConfigurer.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/JMoleculesConfigurer.java new file mode 100644 index 000000000..65efcc50a --- /dev/null +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/config/JMoleculesConfigurer.java @@ -0,0 +1,163 @@ +/* + * Copyright 2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.rest.webmvc.config; + +import java.io.Serializable; +import java.util.function.Supplier; + +import org.jmolecules.ddd.types.Entity; +import org.jmolecules.ddd.types.Identifier; +import org.jmolecules.spring.IdentifierToPrimitivesConverter; +import org.jmolecules.spring.PrimitivesToIdentifierConverter; +import org.springframework.beans.factory.ObjectFactory; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Lazy; +import org.springframework.core.ResolvableType; +import org.springframework.core.convert.ConversionService; +import org.springframework.core.convert.TypeDescriptor; +import org.springframework.core.convert.support.ConfigurableConversionService; +import org.springframework.data.mapping.PersistentEntity; +import org.springframework.data.mapping.PersistentProperty; +import org.springframework.data.mapping.context.PersistentEntities; +import org.springframework.data.rest.webmvc.spi.BackendIdConverter; +import org.springframework.format.FormatterRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * Configuration for JMolecules integration. Registers the following components: + *