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
Hello, I am using Mapstruct to transform data from a JSON format to an XML format for a project at my company. I'm running into some edge case issues where Mapstruct will return an object whose fields are all null, and as such whenever I marshal the object to XML it will come as an empty tag.
e.g. as below:
<Parent>
<Child/> <!-- A child object whose fields are all null -->
<Child>
<FirstName>FirstName</FirstName>
<LastName>LastName</LastName>
</Child>
</Parent>
I would like a way that I could add a custom isAllFieldsNull check at the end of each generated mapping function which would return the object if false or null if true.
@OverridepublicChildXMLchildJSONToChildXML(ChildJSONchildJSON) {
if ( childJSON == null ) {
returnnull;
}
ChildXMLchildXML = newChildXML();
// ... map properties// here is where I would like to be able to add a custom checkif ( isAllFieldsNull(childXML) ) {
returnnull;
}
returnchildXML;
}
I realize this can be resolved with a simple XSLT that removes empty tags, but I also have other requirements such as elements that need to be returned as empty. Please let me know if this check is able to be added in the current implementation of Mapstruct or if this is a feature request that can be added.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I am using Mapstruct to transform data from a JSON format to an XML format for a project at my company. I'm running into some edge case issues where Mapstruct will return an object whose fields are all null, and as such whenever I marshal the object to XML it will come as an empty tag.
e.g. as below:
I would like a way that I could add a custom isAllFieldsNull check at the end of each generated mapping function which would return the object if false or null if true.
I realize this can be resolved with a simple XSLT that removes empty tags, but I also have other requirements such as elements that need to be returned as empty. Please let me know if this check is able to be added in the current implementation of Mapstruct or if this is a feature request that can be added.
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions