You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(unfortunately, GitHub discussions are not enabled in this project).
Background
We've been using MapStruct and implemented each mapper as a Spring Converter. Because of MapStruct's issues with Kotlin, some of which seem unresolvable, we're looking for an alternative and came across ShapeShift.
ShapeShift advertises with "Seamless Spring integration", but it's not that seamless; while there is a starter that automatically registers transformers and decorators, mappers still need to be registered explicitly and ShapeShift doesn't integrate well with Spring's Type Conversion (at least I wouldn't know how and it's not documented).
Issues
A Spring Converter converts from type A to type B. In ShapeShift, we have mappers and MapperTransformer that convert from one type to another. While transformers can rather easily be turned into Converter beans (but still not seamlessly), the same can't be said for mappers as there is no "Mapper" type. As a result, you can't create mapper beans and therefore you can't auto-register them.
There's also ConditionalConverter in Spring and MappingCondition in ShapeShift, but I didn't check if they integrate well.
I tried implementing some adapter code but it seemed impossible. Here's my failed attempt:
importdev.krud.shapeshift.MappingStrategyimportdev.krud.shapeshift.ShapeShiftimportdev.krud.shapeshift.ShapeShiftBuilderimportdev.krud.shapeshift.spring.ShapeShiftBuilderCustomizerimportdev.krud.shapeshift.transformer.base.MappingTransformerimportdev.krud.shapeshift.transformer.base.MappingTransformerContextimportorg.springframework.context.annotation.Configurationimportorg.springframework.core.convert.TypeDescriptorimportorg.springframework.core.convert.converter.Converterimportorg.springframework.core.convert.converter.GenericConverterimportorg.springframework.core.convert.converter.GenericConverter.ConvertiblePair/** * Implements both, ShapeShift's [MappingTransformer] as well as Spring's [Converter]. This * abstracts ShapeShift away from subclasses, so that they can implement Spring's [Converter] * instead.*/abstractclassMappingTransformerConverter<FROM, TO> : Converter<FROM, TO>,
MappingTransformer<FROM, TO> {
finaloverridefuntransform(context:MappingTransformerContext<outFROM>) =
context.originalValue?.let { convert(it) }
}
@Configuration
classMyShapeShiftBuilderCustomizer(
// There seems to be no way to get mapper beansprivatevalmappers:Iterable<NonExistantMapperType>,
) : ShapeShiftBuilderCustomizer {
overridefuncustomize(builder:ShapeShiftBuilder) {
builder
.withDefaultMappingStrategy(MappingStrategy.MAP_ALL)
// This is not valid code
mappers.forEach { builder.withMapping(it) }
}
}
/** A Spring [GenericConverter] that delegates conversion to [ShapeShift]. */classShapeShiftConverter(
privatevalshapeShift:ShapeShift,
) : GenericConverter {
overridefungetConvertibleTypes(): Set<ConvertiblePair> {
// There seems to be no way to get these from ShapeShiftreturn emptySet()
}
overridefunconvert(source:Any?, sourceType:TypeDescriptor, targetType:TypeDescriptor): Any?=
source?.let { shapeShift.map(it, targetType.objectType) }
}
What are your thoughts on this? Is this something you would like to support? Can it be done already but I just didn't see it?
The text was updated successfully, but these errors were encountered:
(unfortunately, GitHub discussions are not enabled in this project).
Background
We've been using MapStruct and implemented each mapper as a Spring
Converter
. Because of MapStruct's issues with Kotlin, some of which seem unresolvable, we're looking for an alternative and came across ShapeShift.ShapeShift advertises with "Seamless Spring integration", but it's not that seamless; while there is a starter that automatically registers transformers and decorators, mappers still need to be registered explicitly and ShapeShift doesn't integrate well with Spring's Type Conversion (at least I wouldn't know how and it's not documented).
Issues
A Spring Converter converts from type A to type B. In ShapeShift, we have mappers and
MapperTransformer
that convert from one type to another. While transformers can rather easily be turned into Converter beans (but still not seamlessly), the same can't be said for mappers as there is no "Mapper" type. As a result, you can't create mapper beans and therefore you can't auto-register them.There's also
ConditionalConverter
in Spring andMappingCondition
in ShapeShift, but I didn't check if they integrate well.I tried implementing some adapter code but it seemed impossible. Here's my failed attempt:
What are your thoughts on this? Is this something you would like to support? Can it be done already but I just didn't see it?
The text was updated successfully, but these errors were encountered: