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
{{ message }}
Repository navigation
Provide example for mapping into ProtoBuf types #14
Is there a way to generify the rule that "permissions" will always be "permissionsList" in the proto? (and vice versa). Otherwise I've updated the example from the pr#25 feedback. Thx.
What do you mean to generify that permisions will always be permissionsList? Do you want to avoid writing @Mapping(source = "permissions", target = "permissionsList") and the opposite?
That can be done by removing the List suffix in the AccessorNamingStrategy#getPropertyName(ExecutableElement getterOrSetterMethod). I don't know protobuf, but you can theoretically check if you are in a proto builder (the same way you are doing now) and check if the return type is List (can it be some other collection?) then strip the List in the end. With this you won't need to adapt the getElementName().
Example with protobuf 3 has been added. My comments are not implemented in the example.
So I have been working through your example and I am at a loss how to get it to work outside of the examples project. Moreso I am using Gradle. This is where I am https://github.com/vordimous/mapstruct-proto
I get this error: warning: Unmapped target properties: "clearField, clearOneof, mergeFrom, idBytes, emailBytes, unknownFields, mergeUnknownFields, allFields, permissionsValueList".
which I can get around by adding a mapping ignore, however you don't have to do this in your example.
I am currently using mapstruct (1.3.0beta1) with Kotlin and gRPC (proto3). The example ProtobufAccessorNamingStrategy doesn't work to handle the mapping between "permissions" and "permissionsList" (the getElementName method doesn't even get called at all). I hate to manually map every collection type explicitly using @ValueMapping, thus did an ugly hack like this and got it working for my purposes:
public class ProtobufAccessorNamingStrategy extends DefaultAccessorNamingStrategy {
/**
* Quick hack to remove the "List" from property name in Protobuf classes
*/ @OverRide
public String getPropertyName(ExecutableElement getterOrSetterMethod) {
String prop = super.getPropertyName(getterOrSetterMethod);
if (prop.endsWith(LIST_SUFFIX)) {
prop = prop.substring(0, prop.length() - 4);
}
return prop;
}
}
Activity
eiswind commentedon May 9, 2017
Is there a way to generify the rule that "permissions" will always be "permissionsList" in the proto? (and vice versa). Otherwise I've updated the example from the pr#25 feedback. Thx.
filiphr commentedon May 9, 2017
What do you mean to generify that
permisionswill always bepermissionsList? Do you want to avoid writing@Mapping(source = "permissions", target = "permissionsList")and the opposite?That can be done by removing the
Listsuffix in theAccessorNamingStrategy#getPropertyName(ExecutableElement getterOrSetterMethod). I don't know protobuf, but you can theoretically check if you are in a proto builder (the same way you are doing now) and check if the return type isList(can it be some other collection?) then strip theListin the end. With this you won't need to adapt thegetElementName().#14 Protobuf example
#14 Add protobuf example to the readme and update to latest MapStruct…
filiphr commentedon Jul 16, 2017
Example with protobuf 3 has been added. My comments are not implemented in the example.
vordimous commentedon Oct 26, 2018
So I have been working through your example and I am at a loss how to get it to work outside of the examples project. Moreso I am using Gradle. This is where I am https://github.com/vordimous/mapstruct-proto
I get this error:
warning: Unmapped target properties: "clearField, clearOneof, mergeFrom, idBytes, emailBytes, unknownFields, mergeUnknownFields, allFields, permissionsValueList".which I can get around by adding a mapping ignore, however you don't have to do this in your example.
Any ideas @filiphr ?
alex-lzl commentedon Oct 30, 2018
I am currently using mapstruct (1.3.0beta1) with Kotlin and gRPC (proto3). The example ProtobufAccessorNamingStrategy doesn't work to handle the mapping between "permissions" and "permissionsList" (the getElementName method doesn't even get called at all). I hate to manually map every collection type explicitly using @ValueMapping, thus did an ugly hack like this and got it working for my purposes:
public class ProtobufAccessorNamingStrategy extends DefaultAccessorNamingStrategy {
/**
* Quick hack to remove the "List" from property name in Protobuf classes
*/
@OverRide
public String getPropertyName(ExecutableElement getterOrSetterMethod) {
String prop = super.getPropertyName(getterOrSetterMethod);
if (prop.endsWith(LIST_SUFFIX)) {
prop = prop.substring(0, prop.length() - 4);
}
return prop;
}
}
Kavyamanjanatha commentedon Dec 5, 2018
@filiphr
Do we have any way to solve the issue reported by alex-lzl?
I am also facing same issue