Reputation: 418
Is it possible to Map an Object called Response with 3 Maps inside it to another Object called ResponseDTO with also 3 Maps
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ResponseDTO implements Serializable {
private Map<String, Map<String, ResponseItemDTO>> map1;
private Map<String, Map<String, ResponseItemDTO>> map2;
private Map<String, Map<String, ResponseItemDTO>> map3;
}
public class ResponseItemDTO implements Serializable {
private String id;
private String label;
private String type;
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "value")
@JsonSubTypes({
@JsonSubTypes.Type(value = SimpleString.class, name = “simpleString"),
@JsonSubTypes.Type(value = OverrideString.class, name = "overrideString")
})
public interface Value {}
}
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@JsonTypeName("simpleString")
public class SimpleString implements ResponseItemDTO {
@JsonProperty("value")
private String value;
}
@Mapper
interface ResponseMapper {
ResponseMapper INSTANCE = Mappers.getMapper(ResponseMapper.class);
@Mapping(target = “map1”, source = "response.map1”)
@Mapping(target = “map2”, source = "response.map2”)
@Mapping(target = “map3”, source = "response.map3”)
ResponseDTO mapResponseDTO(Response response);
//fails and tells me i need to add these mappers
Map<String, Map<String, ResponseItemDTO>> map1(Map<String, ResponseItem> map1);
Map<String,ResponseItemDTO> map(ResponseItem value);
}
My current error is:
java: The return type Map<String,ResponseItemDTO> is an abstract class or interface. Provide a non abstract / non interface result type or a factory method.
I tried creating a concrete class to the Mapper but I’m still getting the same error:
default SimpleString createSimpleString() {
return new SimpleString();
}
Upvotes: 0
Views: 30