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
I have to call some SOAP services through the corresponding WSDL files.
Unfortunately some files have some attributes with dashes. I would expect, that MapStruct can map those fields using the corresponding ObjectFactory class.
In this PR a comment even mentioned to use a regex to match underscores and dashes, but the latter never made it into this PR.
MapStruct cannot handle the dash inside of the element name. I get a Ambiguous mapping methods found for mapping property error as it cannot find the specific mapping method of the ObjectFactory
Example:
Element:
Manipulate the Jaxb integration test to use a dash instead of the camel case parameter. It should generate the field in camel case but the mapping breaks afterwards.
I guess I found the problem. Mapstruct is trying to resolve the setter methods but the problem is another one. It's not mainly the dash itself but the generation of those classes lead to this problem.
Explained:
<-- Part of the WSDL -->
<elementname="XY-Something"type="int"minOccurs="0"nillable="true"/>
// Generated field from class MyClass.class using cxf:@XmlElementRef(name = "XY-Something", namespace = "http://mynamespace", type = JAXBElement.class, required = false)
protectedJAXBElement<Integer> xySomething;
publicvoidsetXYSomething(JAXBElement<Integer> value) {
this.xySomething = value;
}
I generate my DTO from the named WSDL. So Mapstruct tries to find the member XYSomething as this is also the get method for this property. The processor class XmlElementDeclSelector tries to find the field inside of MyClass otherwise it just takes the target property name which is "XYSomething". In the loop of getMatchingMethods inside of XmlElementDeclSelector the XML declaration name of each property is taken which result in "XY-Something" and thus nameIsSetAndMatches is false as it will be compared with "XYSomething".
Maybe a solution would be to sanitize the dash in the JakartaXmlElementDeclSelector and JakartaXmlElementDeclSelector classes, but that's for you to decide.
Edit:
/* * Copyright MapStruct Authors. * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */classJavaxXmlElementDeclSelectorextendsXmlElementDeclSelector {
JavaxXmlElementDeclSelector(TypeUtilstypeUtils) {
super( typeUtils );
}
@OverrideXmlElementDeclInfogetXmlElementDeclInfo(Elementelement) {
XmlElementDeclGemgem = XmlElementDeclGem.instanceOn( element );
if (gem == null) {
returnnull;
}
returnnewXmlElementDeclInfo( gem.name().get().replaceAll("-",""), gem.scope().get() );
}
@OverrideXmlElementRefInfogetXmlElementRefInfo(Elementelement) {
XmlElementRefGemgem = XmlElementRefGem.instanceOn( element );
if (gem == null) {
returnnull;
}
returnnewXmlElementRefInfo( gem.name().get().replaceAll("-",""), gem.type().get() );
}
}
Just a smell modification that solves the problem with passing all unit tests.
Activity
Selfmade-RuLeZ commentedon Sep 12, 2025
I guess I found the problem. Mapstruct is trying to resolve the setter methods but the problem is another one. It's not mainly the dash itself but the generation of those classes lead to this problem.
Explained:
I generate my DTO from the named WSDL. So Mapstruct tries to find the member XYSomething as this is also the get method for this property. The processor class
XmlElementDeclSelectortries to find the field inside of MyClass otherwise it just takes the target property name which is "XYSomething". In the loop ofgetMatchingMethodsinside ofXmlElementDeclSelectorthe XML declaration name of each property is taken which result in "XY-Something" and thusnameIsSetAndMatchesis false as it will be compared with "XYSomething".Maybe a solution would be to sanitize the dash in the
JakartaXmlElementDeclSelectorandJakartaXmlElementDeclSelectorclasses, but that's for you to decide.Edit:
Just a smell modification that solves the problem with passing all unit tests.