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
To support something like this we would have to provide a custom support for mapping to Map.Entry and to treat Map<K,V> as Iterable<Map.Entry<K,V>> when mapping a map into an iterable.
Originally posted by hinrik May 5, 2023
I sometimes want to flatten a map into a list (and vice versa), e.g. when I'm converting from different representations (e.g. Avro to/from application domain). I have to do the entire mapping with a default method on my mapper interface, duplicating some logic that MapStruct could have taken care of for me.
Here I wish I could do something like @Mapping(target = "schedule", source = "flatSchedule", flatKey = "day"). which would also work if source and target were flipped.
This example is similar, except here the value in the source map is not a bean, so we need to introduce a key for it in the target map. Here I wish I could do @Mapping(target = "schedule", source = "flatSchedule", flatKey = "day", flatValue = "times").
Would this be worth implementing in MapStruct?
The text was updated successfully, but these errors were encountered:
The main idea is to offer mapping from a list into a map and vice versa. This could be done by treating the map as an
Iterable<Map.Entry<K,V>>
.This would me that we could do something like:
and the reverse could look like:
To support something like this we would have to provide a custom support for mapping to
Map.Entry
and to treatMap<K,V>
asIterable<Map.Entry<K,V>>
when mapping a map into an iterable.Discussed in #3263
Originally posted by hinrik May 5, 2023
I sometimes want to flatten a map into a list (and vice versa), e.g. when I'm converting from different representations (e.g. Avro to/from application domain). I have to do the entire mapping with a
default
method on my mapper interface, duplicating some logic that MapStruct could have taken care of for me.There are two general use cases I run into.
Flattening a multi-value map
Target:
Here I wish I could do something like
@Mapping(target = "schedule", source = "flatSchedule", flatKey = "day")
. which would also work ifsource
andtarget
were flipped.Flattening a single-value map
Source:
Target:
This example is similar, except here the value in the source map is not a bean, so we need to introduce a key for it in the target map. Here I wish I could do
@Mapping(target = "schedule", source = "flatSchedule", flatKey = "day", flatValue = "times")
.Would this be worth implementing in MapStruct?
The text was updated successfully, but these errors were encountered: