Failed to map List<String> to repeated string field of protocol buffer

2,526 views
Skip to first unread message

Francis Ip

unread,
Jan 29, 2018, 2:02:57 AM1/29/18
to mapstruct-users

Thank you so much for adding the Proto example. The example works.


But I failed to mapList<String>



I added the follow field to the proto

repeated string allowed_drivers;


Also added a List<String> permittedDrivers field to the POJO. 

Because the Java class generated from the target protocol buffer has a method of Builder#getAllowedDriversList(), whose return type is ProtocolStringList, which is a sub-class of List<String>, I added a BuidlerFactory method that returns a new, empty, and mutable impl object of ProtocolStringList.

However, I still failed to create mappings between these two collection fields. 


The crux of the issue is:


The generated codes still tries to do:

builderr.getAllowedDriversList().addAll(sourcePojo.getPermittedDrivers());

Instead of doing the builder.add() operation like the permissions.


This piece of generated codes failed in run time because targetProtoBuilder.getAllowedDriversList() returns an immutable ProtocolStringList, which throws UnsupportedException on the its addAll() method.


Can someone give some pointers on how to make 'repeated string' field works?



Thanks a lot.

Filip Hrisafov

unread,
Jan 29, 2018, 5:44:48 PM1/29/18
to mapstruct-users
Hi Francis,

We already have an open issue for this. Have a look at #1338. Look at my reply there for a solution.

If you are interested you can also provide a PR with the fix.

Cheers,
Filip

Francis Ip

unread,
Jan 30, 2018, 6:11:59 AM1/30/18
to Filip Hrisafov, mapstruct-users

Filip

 My understanding after reading #1338 is that the solution is not yet publicly available? What is a PR?

--
You received this message because you are subscribed to a topic in the Google Groups "mapstruct-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mapstruct-users/cTjkHrlsnuI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mapstruct-use...@googlegroups.com.
To post to this group, send email to mapstru...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gunnar Morling

unread,
Jan 30, 2018, 12:37:03 PM1/30/18
to Francis Ip, Filip Hrisafov, mapstruct-users
A PR is a "pull request", i.e. a proposed change with a feature or bugfix implementation. See here: https://help.github.com/articles/about-pull-requests/

--Gunnar


2018-01-30 12:11 GMT+01:00 Francis Ip <fai...@gmail.com>:

Filip

 My understanding after reading #1338 is that the solution is not yet publicly available? What is a PR?

On Mon, Jan 29, 2018 at 2:44 PM Filip Hrisafov <filip.h...@gmail.com> wrote:
Hi Francis,

We already have an open issue for this. Have a look at #1338. Look at my reply there for a solution.

If you are interested you can also provide a PR with the fix.

Cheers,
Filip

--
You received this message because you are subscribed to a topic in the Google Groups "mapstruct-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mapstruct-users/cTjkHrlsnuI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mapstruct-users+unsubscribe@googlegroups.com.
To post to this group, send email to mapstruct-users@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mapstruct-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapstruct-users+unsubscribe@googlegroups.com.
To post to this group, send email to mapstruct-users@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages