In My dto class :
private String password;
In my model class:
private byte[] password;
I want to convert String to byte[] using mapStruct. Can someone help
Thanks in advance.
Best would be to provide a default method for mapping between String
and byte[]
.
For example:
@Mapper
public MyMapper {
Model fromDto(Dto dto);
default byte[] toBytes(String string) {
return string != null ? string.getBytes() : null;
}
}
With this you will have MapStruct do automatic for all of your other fields between Dto
and Model
and leave the mapping between String
and byte[]
to the toBytes
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With