Discussion:
Serialization Problem for Streams' Lambda used in Spring beans
m.xinu
2018-06-20 15:38:00 UTC
Permalink
Hi,

I'm using Apache Wicket 7.9.0 alongside Spring 5.0.5.RELEASE. In one of my beans, I call some stream API containing multiple lambda expressions. During that page execution, I get following exception:

Caused by: java.io.NotSerializableException: org.devocative.metis.service.data.ReportService$$Lambda$126/997816965

and it is very strange for me since it is in one of my beans not in any Wicket-related part.

I've searched and I've found the Serializable casting solution, however it results in a very complex syntax for my code. So is there any other solution? Dose Wicket has a way for this type of serialization?


P.S: My block of code for stream:

reports.parallelStream()
.filter(report ->
externalAuthorizationService == null ||
externalAuthorizationService.authorizeReport(report, null, currentUser.getUserId())
)
.flatMap(report -> report.getGroups().stream().map(dataGroup -> new KeyValueVO<>(dataGroup, report)))
.collect(Collectors.groupingBy(
KeyValueVO::getKey,
() -> new TreeMap<>(Comparator.comparing(DataGroup::getName)),
Collectors.mapping(
KeyValueVO::getValue,
Collectors.toList()))
);
Maxim Solodovnik
2018-06-21 01:13:37 UTC
Permalink
https://cwiki.apache.org/confluence/display/WICKET/Migration+to+Wicket+8.0#MigrationtoWicket8.0-Provideserializableversionsofjava.util.function.(Supplier|Consumer|Function|BiConsumer)ASFJIRA5aa69414-a9e9-3523-82ec-879b028fb15bWICKET-5991

WBR, Maxim
(from mobile, sorry for the typos)
Post by m.xinu
Hi,
I'm using Apache Wicket 7.9.0 alongside Spring 5.0.5.RELEASE. In one of my
beans, I call some stream API containing multiple lambda expressions.
org.devocative.metis.service.data.ReportService$$Lambda$126/997816965
and it is very strange for me since it is in one of my beans not in any
Wicket-related part.
I've searched and I've found the Serializable casting solution, however it
results in a very complex syntax for my code. So is there any other
solution? Dose Wicket has a way for this type of serialization?
reports.parallelStream()
.filter(report ->
externalAuthorizationService == null ||
externalAuthorizationService.authorizeReport(report, null,
currentUser.getUserId())
)
.flatMap(report -> report.getGroups().stream().map(dataGroup -> new
KeyValueVO<>(dataGroup, report)))
.collect(Collectors.groupingBy(
KeyValueVO::getKey,
() -> new TreeMap<>(Comparator.comparing(DataGroup::getName)),
Collectors.mapping(
KeyValueVO::getValue,
Collectors.toList()))
);
Maxim Solodovnik
2018-06-21 01:15:14 UTC
Permalink
Wicket7:
https://github.com/wicketstuff/core/blob/wicket-7.x/lambda-parent/lambda/src/main/java/org/wicketstuff/lambda/SerializableBiConsumer.java

WBR, Maxim
(from mobile, sorry for the typos)
Post by Maxim Solodovnik
https://cwiki.apache.org/confluence/display/WICKET/Migration+to+Wicket+8.0#MigrationtoWicket8.0-Provideserializableversionsofjava.util.function.(Supplier|Consumer|Function|BiConsumer)ASFJIRA5aa69414-a9e9-3523-82ec-879b028fb15bWICKET-5991
<https://cwiki.apache.org/confluence/display/WICKET/Migration+to+Wicket+8.0#MigrationtoWicket8.0-Provideserializableversionsofjava.util.function.(Supplier%7CConsumer%7CFunction%7CBiConsumer)ASFJIRA5aa69414-a9e9-3523-82ec-879b028fb15bWICKET-5991>
WBR, Maxim
(from mobile, sorry for the typos)
Post by m.xinu
Hi,
I'm using Apache Wicket 7.9.0 alongside Spring 5.0.5.RELEASE. In one of
my beans, I call some stream API containing multiple lambda expressions.
org.devocative.metis.service.data.ReportService$$Lambda$126/997816965
and it is very strange for me since it is in one of my beans not in any
Wicket-related part.
I've searched and I've found the Serializable casting solution, however
it results in a very complex syntax for my code. So is there any other
solution? Dose Wicket has a way for this type of serialization?
reports.parallelStream()
.filter(report ->
externalAuthorizationService == null ||
externalAuthorizationService.authorizeReport(report, null,
currentUser.getUserId())
)
.flatMap(report -> report.getGroups().stream().map(dataGroup -> new
KeyValueVO<>(dataGroup, report)))
.collect(Collectors.groupingBy(
KeyValueVO::getKey,
() -> new TreeMap<>(Comparator.comparing(DataGroup::getName)),
Collectors.mapping(
KeyValueVO::getValue,
Collectors.toList()))
);
m.xinu
2018-06-21 10:45:30 UTC
Permalink
Thanks for your reply.

Both of your proposed solutions mean using other interfaces in the Lambda expressions. However most of my Lambda definitions are in my Service tier classes (Spring beans), and the Service tier must be independent from the Web tier, and the force of Wicket serialization (even for the service beans) breaks the aforementioned rule. Is there another solution? Is it possible for Wicket not to serialize the Spring beans? or is there another serialization mechanism in Wicket not based on Serializable interface?


On Thursday, June 21, 2018, 5:44:00 AM GMT+4:30, Maxim Solodovnik <***@gmail.com> wrote:

Wicket7:
https://github.com/wicketstuff/core/blob/wicket-7.x/lambda-parent/lambda/src/main/java/org/wicketstuff/lambda/SerializableBiConsumer.java

WBR, Maxim
(from mobile, sorry for the typos)
Post by Maxim Solodovnik
https://cwiki.apache.org/confluence/display/WICKET/Migration+to+Wicket+8.0#MigrationtoWicket8.0-Provideserializableversionsofjava.util.function.(Supplier|Consumer|Function|BiConsumer)ASFJIRA5aa69414-a9e9-3523-82ec-879b028fb15bWICKET-5991
<https://cwiki.apache.org/confluence/display/WICKET/Migration+to+Wicket+8.0#MigrationtoWicket8.0-Provideserializableversionsofjava.util.function.(Supplier%7CConsumer%7CFunction%7CBiConsumer)ASFJIRA5aa69414-a9e9-3523-82ec-879b028fb15bWICKET-5991>
WBR, Maxim
(from mobile, sorry for the typos)
Post by m.xinu
Hi,
I'm using Apache Wicket 7.9.0 alongside Spring 5.0.5.RELEASE. In one of
my beans, I call some stream API containing multiple lambda expressions.
org.devocative.metis.service.data.ReportService$$Lambda$126/997816965
and it is very strange for me since it is in one of my beans not in any
Wicket-related part.
I've searched and I've found the Serializable casting solution, however
it results in a very complex syntax for my code. So is there any other
solution? Dose Wicket has a way for this type of serialization?
reports.parallelStream()
    .filter(report ->
      externalAuthorizationService == null ||
          externalAuthorizationService.authorizeReport(report, null,
currentUser.getUserId())
    )
    .flatMap(report -> report.getGroups().stream().map(dataGroup -> new
KeyValueVO<>(dataGroup, report)))
    .collect(Collectors.groupingBy(
      KeyValueVO::getKey,
      () -> new TreeMap<>(Comparator.comparing(DataGroup::getName)),
      Collectors.mapping(
          KeyValueVO::getValue,
          Collectors.toList()))
    );
Andrea Del Bene
2018-06-21 11:00:18 UTC
Permalink
I think you are keeping a reference to your Spring bean in a page or in a
component, that's why Wicket is trying to serialize it. Are you injecting
Post by m.xinu
Thanks for your reply.
Both of your proposed solutions mean using other interfaces in the Lambda
expressions. However most of my Lambda definitions are in my Service tier
classes (Spring beans), and the Service tier must be independent from the
Web tier, and the force of Wicket serialization (even for the service
beans) breaks the aforementioned rule. Is there another solution? Is it
possible for Wicket not to serialize the Spring beans? or is there another
serialization mechanism in Wicket not based on Serializable interface?
On Thursday, June 21, 2018, 5:44:00 AM GMT+4:30, Maxim Solodovnik <
https://github.com/wicketstuff/core/blob/wicket-
7.x/lambda-parent/lambda/src/main/java/org/wicketstuff/
lambda/SerializableBiConsumer.java
WBR, Maxim
(from mobile, sorry for the typos)
Post by Maxim Solodovnik
https://cwiki.apache.org/confluence/display/WICKET/
Migration+to+Wicket+8.0#MigrationtoWicket8.0-
Provideserializableversionsofjava.util.function.(Supplier|
Consumer|Function|BiConsumer)ASFJIRA5aa69414-a9e9-3523-
82ec-879b028fb15bWICKET-5991
Post by Maxim Solodovnik
<https://cwiki.apache.org/confluence/display/WICKET/
Migration+to+Wicket+8.0#MigrationtoWicket8.0-
Provideserializableversionsofjava.util.function.(Supplier%
7CConsumer%7CFunction%7CBiConsumer)ASFJIRA5aa69414-a9e9-3523-82ec-
879b028fb15bWICKET-5991>
Post by Maxim Solodovnik
WBR, Maxim
(from mobile, sorry for the typos)
Post by m.xinu
Hi,
I'm using Apache Wicket 7.9.0 alongside Spring 5.0.5.RELEASE. In one of
my beans, I call some stream API containing multiple lambda expressions.
org.devocative.metis.service.data.ReportService$$Lambda$126/997816965
and it is very strange for me since it is in one of my beans not in any
Wicket-related part.
I've searched and I've found the Serializable casting solution, however
it results in a very complex syntax for my code. So is there any other
solution? Dose Wicket has a way for this type of serialization?
reports.parallelStream()
.filter(report ->
externalAuthorizationService == null ||
externalAuthorizationService.authorizeReport(report, null,
currentUser.getUserId())
)
.flatMap(report -> report.getGroups().stream().map(dataGroup -> new
KeyValueVO<>(dataGroup, report)))
.collect(Collectors.groupingBy(
KeyValueVO::getKey,
() -> new TreeMap<>(Comparator.comparing(DataGroup::getName)),
Collectors.mapping(
KeyValueVO::getValue,
Collectors.toList()))
);
m.xinu
2018-06-21 11:26:11 UTC
Permalink
I manually create the Spring context, which is ClassPathXmlApplicationContext, and pass it to Wicket application by calling

    getComponentInstantiationListeners().add(new SpringComponentInjector(this, MyApp.get().getApplicationContext())).

Then, In my panel I have this

    private class ReportMenuPanel extends WPanel {
        private static final long serialVersionUID = -9012565863392514416L;

        @Inject
        private IReportService reportService;

        ...
    }

I also checked my code with @SpringBean and I got the same exception.


On Thursday, June 21, 2018, 3:30:29 PM GMT+4:30, Andrea Del Bene <***@gmail.com> wrote:

I think you are keeping a reference to your Spring bean in a page or in a
component, that's why Wicket is trying to serialize it. Are you injecting
Post by m.xinu
Thanks for your reply.
Both of your proposed solutions mean using other interfaces in the Lambda
expressions. However most of my Lambda definitions are in my Service tier
classes (Spring beans), and the Service tier must be independent from the
Web tier, and the force of Wicket serialization (even for the service
beans) breaks the aforementioned rule. Is there another solution? Is it
possible for Wicket not to serialize the Spring beans? or is there another
serialization mechanism in Wicket not based on Serializable interface?
    On Thursday, June 21, 2018, 5:44:00 AM GMT+4:30, Maxim Solodovnik <
https://github.com/wicketstuff/core/blob/wicket-
7.x/lambda-parent/lambda/src/main/java/org/wicketstuff/
lambda/SerializableBiConsumer.java
WBR, Maxim
(from mobile, sorry for the typos)
Post by Maxim Solodovnik
https://cwiki.apache.org/confluence/display/WICKET/
Migration+to+Wicket+8.0#MigrationtoWicket8.0-
Provideserializableversionsofjava.util.function.(Supplier|
Consumer|Function|BiConsumer)ASFJIRA5aa69414-a9e9-3523-
82ec-879b028fb15bWICKET-5991
Post by Maxim Solodovnik
<https://cwiki.apache.org/confluence/display/WICKET/
Migration+to+Wicket+8.0#MigrationtoWicket8.0-
Provideserializableversionsofjava.util.function.(Supplier%
7CConsumer%7CFunction%7CBiConsumer)ASFJIRA5aa69414-a9e9-3523-82ec-
879b028fb15bWICKET-5991>
Post by Maxim Solodovnik
WBR, Maxim
(from mobile, sorry for the typos)
Post by m.xinu
Hi,
I'm using Apache Wicket 7.9.0 alongside Spring 5.0.5.RELEASE. In one of
my beans, I call some stream API containing multiple lambda expressions.
org.devocative.metis.service.data.ReportService$$Lambda$126/997816965
and it is very strange for me since it is in one of my beans not in any
Wicket-related part.
I've searched and I've found the Serializable casting solution, however
it results in a very complex syntax for my code. So is there any other
solution? Dose Wicket has a way for this type of serialization?
reports.parallelStream()
    .filter(report ->
      externalAuthorizationService == null ||
          externalAuthorizationService.authorizeReport(report, null,
currentUser.getUserId())
    )
    .flatMap(report -> report.getGroups().stream().map(dataGroup -> new
KeyValueVO<>(dataGroup, report)))
    .collect(Collectors.groupingBy(
      KeyValueVO::getKey,
      () -> new TreeMap<>(Comparator.comparing(DataGroup::getName)),
      Collectors.mapping(
          KeyValueVO::getValue,
          Collectors.toList()))
    );
Andrea Del Bene
2018-06-21 12:08:49 UTC
Permalink
That's strange. Could you show the full exception stack trace?
Post by m.xinu
I manually create the Spring context, which is
ClassPathXmlApplicationContext, and pass it to Wicket application by
calling
getComponentInstantiationListeners().add(new
SpringComponentInjector(this, MyApp.get().getApplicationContext())).
Then, In my panel I have this
private class ReportMenuPanel extends WPanel {
private static final long serialVersionUID = -9012565863392514416L;
@Inject
private IReportService reportService;
...
}
On Thursday, June 21, 2018, 3:30:29 PM GMT+4:30, Andrea Del Bene <
I think you are keeping a reference to your Spring bean in a page or in a
component, that's why Wicket is trying to serialize it. Are you injecting
Post by m.xinu
Thanks for your reply.
Both of your proposed solutions mean using other interfaces in the Lambda
expressions. However most of my Lambda definitions are in my Service tier
classes (Spring beans), and the Service tier must be independent from the
Web tier, and the force of Wicket serialization (even for the service
beans) breaks the aforementioned rule. Is there another solution? Is it
possible for Wicket not to serialize the Spring beans? or is there
another
Post by m.xinu
serialization mechanism in Wicket not based on Serializable interface?
On Thursday, June 21, 2018, 5:44:00 AM GMT+4:30, Maxim Solodovnik <
https://github.com/wicketstuff/core/blob/wicket-
7.x/lambda-parent/lambda/src/main/java/org/wicketstuff/
lambda/SerializableBiConsumer.java
WBR, Maxim
(from mobile, sorry for the typos)
Post by Maxim Solodovnik
https://cwiki.apache.org/confluence/display/WICKET/
Migration+to+Wicket+8.0#MigrationtoWicket8.0-
Provideserializableversionsofjava.util.function.(Supplier|
Consumer|Function|BiConsumer)ASFJIRA5aa69414-a9e9-3523-
82ec-879b028fb15bWICKET-5991
Post by Maxim Solodovnik
<https://cwiki.apache.org/confluence/display/WICKET/
Migration+to+Wicket+8.0#MigrationtoWicket8.0-
Provideserializableversionsofjava.util.function.(Supplier%
7CConsumer%7CFunction%7CBiConsumer)ASFJIRA5aa69414-a9e9-3523-82ec-
879b028fb15bWICKET-5991>
Post by Maxim Solodovnik
WBR, Maxim
(from mobile, sorry for the typos)
Post by m.xinu
Hi,
I'm using Apache Wicket 7.9.0 alongside Spring 5.0.5.RELEASE. In one
of
Post by m.xinu
Post by Maxim Solodovnik
Post by m.xinu
my beans, I call some stream API containing multiple lambda
expressions.
Post by m.xinu
Post by Maxim Solodovnik
Post by m.xinu
org.devocative.metis.service.data.ReportService$$Lambda$126/997816965
and it is very strange for me since it is in one of my beans not in
any
Post by m.xinu
Post by Maxim Solodovnik
Post by m.xinu
Wicket-related part.
I've searched and I've found the Serializable casting solution,
however
Post by m.xinu
Post by Maxim Solodovnik
Post by m.xinu
it results in a very complex syntax for my code. So is there any other
solution? Dose Wicket has a way for this type of serialization?
reports.parallelStream()
.filter(report ->
externalAuthorizationService == null ||
externalAuthorizationService.authorizeReport(report, null,
currentUser.getUserId())
)
.flatMap(report -> report.getGroups().stream().map(dataGroup ->
new
Post by m.xinu
Post by Maxim Solodovnik
Post by m.xinu
KeyValueVO<>(dataGroup, report)))
.collect(Collectors.groupingBy(
KeyValueVO::getKey,
() -> new TreeMap<>(Comparator.comparing(DataGroup::getName)),
Collectors.mapping(
KeyValueVO::getValue,
Collectors.toList()))
);
Sven Meier
2018-06-21 12:18:18 UTC
Permalink
Hi,

your service method is return a TreeMap holding a lambda comparator:

Comparator.comparing(DataGroup::getName)

Either you make that comparator serializable (you can but you don't *need* to use org.danekja as Wicket does it):

https://stackoverflow.com/questions/22807912/how-to-serialize-a-lambda

... or don't keep the result of your service method in the Wicket component tree, e.g. by using a LoadableDetachableModel.

Have fun
Sven
Post by m.xinu
I manually create the Spring context, which is ClassPathXmlApplicationContext, and pass it to Wicket application by calling
    getComponentInstantiationListeners().add(new SpringComponentInjector(this, MyApp.get().getApplicationContext())).
Then, In my panel I have this
    private class ReportMenuPanel extends WPanel {
        private static final long serialVersionUID = -9012565863392514416L;
        private IReportService reportService;
        ...
    }
I think you are keeping a reference to your Spring bean in a page or in a
component, that's why Wicket is trying to serialize it. Are you injecting
Post by m.xinu
Thanks for your reply.
Both of your proposed solutions mean using other interfaces in the Lambda
expressions. However most of my Lambda definitions are in my Service tier
classes (Spring beans), and the Service tier must be independent from the
Web tier, and the force of Wicket serialization (even for the service
beans) breaks the aforementioned rule. Is there another solution? Is it
possible for Wicket not to serialize the Spring beans? or is there another
serialization mechanism in Wicket not based on Serializable interface?
    On Thursday, June 21, 2018, 5:44:00 AM GMT+4:30, Maxim Solodovnik <
https://github.com/wicketstuff/core/blob/wicket-
7.x/lambda-parent/lambda/src/main/java/org/wicketstuff/
lambda/SerializableBiConsumer.java
WBR, Maxim
(from mobile, sorry for the typos)
Post by Maxim Solodovnik
https://cwiki.apache.org/confluence/display/WICKET/
Migration+to+Wicket+8.0#MigrationtoWicket8.0-
Provideserializableversionsofjava.util.function.(Supplier|
Consumer|Function|BiConsumer)ASFJIRA5aa69414-a9e9-3523-
82ec-879b028fb15bWICKET-5991
Post by Maxim Solodovnik
<https://cwiki.apache.org/confluence/display/WICKET/
Migration+to+Wicket+8.0#MigrationtoWicket8.0-
Provideserializableversionsofjava.util.function.(Supplier%
7CConsumer%7CFunction%7CBiConsumer)ASFJIRA5aa69414-a9e9-3523-82ec-
879b028fb15bWICKET-5991>
Post by Maxim Solodovnik
WBR, Maxim
(from mobile, sorry for the typos)
Post by m.xinu
Hi,
I'm using Apache Wicket 7.9.0 alongside Spring 5.0.5.RELEASE. In one of
my beans, I call some stream API containing multiple lambda expressions.
org.devocative.metis.service.data.ReportService$$Lambda$126/997816965
and it is very strange for me since it is in one of my beans not in any
Wicket-related part.
I've searched and I've found the Serializable casting solution, however
it results in a very complex syntax for my code. So is there any other
solution? Dose Wicket has a way for this type of serialization?
reports.parallelStream()
    .filter(report ->
      externalAuthorizationService == null ||
          externalAuthorizationService.authorizeReport(report, null,
currentUser.getUserId())
    )
    .flatMap(report -> report.getGroups().stream().map(dataGroup -> new
KeyValueVO<>(dataGroup, report)))
    .collect(Collectors.groupingBy(
      KeyValueVO::getKey,
      () -> new TreeMap<>(Comparator.comparing(DataGroup::getName)),
      Collectors.mapping(
          KeyValueVO::getValue,
          Collectors.toList()))
    );
---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org
m.xinu
2018-06-21 14:38:27 UTC
Permalink
yes, thank you, that's the reason! The problem is the Comparator in TreeMap.

I prefer to use your second proposed solution, however my service returns Map<DataGroup, List<Report>> and I render the result in two nested ListView as follows:

            final Map<DataGroup, List<Report>> listPerGroup = reportService.listPerGroup();

            add(new ListView<DataGroup>("group", new ArrayList<>(listPerGroup.keySet())) {

                @Override
                protected void populateItem(ListItem<DataGroup> groupItem) {
                    DataGroup group = groupItem.getModelObject();                    ...

                    groupItem.add(new ListView<Report>("report", listPerGroup.get(group)) {

                        @Override
                        protected void populateItem(ListItem<Report> item) {
                            final Report report = item.getModelObject();                            ...
                        }
                    });
                }
            });

In this approach, is it possible to use LoadableDetachableModel or I must change my return type? I want to learn the Wicket way.
On Thursday, June 21, 2018, 4:48:25 PM GMT+4:30, Sven Meier <***@meiers.net> wrote:

Hi,

your service method is return a TreeMap holding a lambda comparator:

    Comparator.comparing(DataGroup::getName)

Either you make that comparator serializable (you can but you don't *need* to use org.danekja as Wicket does it):

    https://stackoverflow.com/questions/22807912/how-to-serialize-a-lambda

... or don't keep the result of your service method in the Wicket component tree, e.g. by using a LoadableDetachableModel.

Have fun
Sven
Post by m.xinu
I manually create the Spring context, which is ClassPathXmlApplicationContext, and pass it to Wicket application by calling
      getComponentInstantiationListeners().add(new SpringComponentInjector(this, MyApp.get().getApplicationContext())).
Then, In my panel I have this
      private class ReportMenuPanel extends WPanel {
          private static final long serialVersionUID = -9012565863392514416L;
          private IReportService reportService;
          ...
      }
 
 
  I think you are keeping a reference to your Spring bean in a page or in a
component, that's why Wicket is trying to serialize it. Are you injecting
Post by m.xinu
Thanks for your reply.
Both of your proposed solutions mean using other interfaces in the Lambda
expressions. However most of my Lambda definitions are in my Service tier
classes (Spring beans), and the Service tier must be independent from the
Web tier, and the force of Wicket serialization (even for the service
beans) breaks the aforementioned rule. Is there another solution? Is it
possible for Wicket not to serialize the Spring beans? or is there another
serialization mechanism in Wicket not based on Serializable interface?
      On Thursday, June 21, 2018, 5:44:00 AM GMT+4:30, Maxim Solodovnik <
https://github.com/wicketstuff/core/blob/wicket-
7.x/lambda-parent/lambda/src/main/java/org/wicketstuff/
lambda/SerializableBiConsumer.java
WBR, Maxim
(from mobile, sorry for the typos)
Post by Maxim Solodovnik
https://cwiki.apache.org/confluence/display/WICKET/
Migration+to+Wicket+8.0#MigrationtoWicket8.0-
Provideserializableversionsofjava.util.function.(Supplier|
Consumer|Function|BiConsumer)ASFJIRA5aa69414-a9e9-3523-
82ec-879b028fb15bWICKET-5991
Post by Maxim Solodovnik
<https://cwiki.apache.org/confluence/display/WICKET/
Migration+to+Wicket+8.0#MigrationtoWicket8.0-
Provideserializableversionsofjava.util.function.(Supplier%
7CConsumer%7CFunction%7CBiConsumer)ASFJIRA5aa69414-a9e9-3523-82ec-
879b028fb15bWICKET-5991>
Post by Maxim Solodovnik
WBR, Maxim
(from mobile, sorry for the typos)
Post by m.xinu
Hi,
I'm using Apache Wicket 7.9.0 alongside Spring 5.0.5.RELEASE. In one of
my beans, I call some stream API containing multiple lambda expressions.
org.devocative.metis.service.data.ReportService$$Lambda$126/997816965
and it is very strange for me since it is in one of my beans not in any
Wicket-related part.
I've searched and I've found the Serializable casting solution, however
it results in a very complex syntax for my code. So is there any other
solution? Dose Wicket has a way for this type of serialization?
reports.parallelStream()
      .filter(report ->
        externalAuthorizationService == null ||
            externalAuthorizationService.authorizeReport(report, null,
currentUser.getUserId())
      )
      .flatMap(report -> report.getGroups().stream().map(dataGroup -> new
KeyValueVO<>(dataGroup, report)))
      .collect(Collectors.groupingBy(
        KeyValueVO::getKey,
        () -> new TreeMap<>(Comparator.comparing(DataGroup::getName)),
        Collectors.mapping(
            KeyValueVO::getValue,
            Collectors.toList()))
      );
   
---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org
Sven Meier
2018-06-21 16:14:33 UTC
Permalink
Wicket way:

        final IModel<Map<DataGroup, List<Report>>> listPerGroup =
LoadableDetachableModel.of(() -> reportService.listPerGroup());

        add(new ListView<DataGroup>("group", () -> new
ArrayList<>(listPerGroup.getObject().keySet())) {
            @Override
            protected void populateItem(ListItem<DataGroup> groupItem) {
                groupItem.add(new ListView<Report>("report", () ->
listPerGroup.getObject().get(groupItem.getModelObject())) {
                    @Override
                    protected void populateItem(ListItem<Report> item) {
                        // try not to call getModelObject() too early,
use models instead
                        final Report report = item.getModelObject();
                    }
                });
            }
        });

Have fun
Sven
Post by m.xinu
yes, thank you, that's the reason! The problem is the Comparator in TreeMap.
            final Map<DataGroup, List<Report>> listPerGroup = reportService.listPerGroup();
            add(new ListView<DataGroup>("group", new ArrayList<>(listPerGroup.keySet())) {
                protected void populateItem(ListItem<DataGroup> groupItem) {
                    DataGroup group = groupItem.getModelObject();                    ...
                    groupItem.add(new ListView<Report>("report", listPerGroup.get(group)) {
                        protected void populateItem(ListItem<Report> item) {
                            final Report report = item.getModelObject();                            ...
                        }
                    });
                }
            });
In this approach, is it possible to use LoadableDetachableModel or I must change my return type? I want to learn the Wicket way.
Hi,
    Comparator.comparing(DataGroup::getName)
    https://stackoverflow.com/questions/22807912/how-to-serialize-a-lambda
... or don't keep the result of your service method in the Wicket component tree, e.g. by using a LoadableDetachableModel.
Have fun
Sven
Post by m.xinu
I manually create the Spring context, which is ClassPathXmlApplicationContext, and pass it to Wicket application by calling
      getComponentInstantiationListeners().add(new SpringComponentInjector(this, MyApp.get().getApplicationContext())).
Then, In my panel I have this
      private class ReportMenuPanel extends WPanel {
          private static final long serialVersionUID = -9012565863392514416L;
          private IReportService reportService;
          ...
      }
  I think you are keeping a reference to your Spring bean in a page or in a
component, that's why Wicket is trying to serialize it. Are you injecting
Post by m.xinu
Thanks for your reply.
Both of your proposed solutions mean using other interfaces in the Lambda
expressions. However most of my Lambda definitions are in my Service tier
classes (Spring beans), and the Service tier must be independent from the
Web tier, and the force of Wicket serialization (even for the service
beans) breaks the aforementioned rule. Is there another solution? Is it
possible for Wicket not to serialize the Spring beans? or is there another
serialization mechanism in Wicket not based on Serializable interface?
      On Thursday, June 21, 2018, 5:44:00 AM GMT+4:30, Maxim Solodovnik <
https://github.com/wicketstuff/core/blob/wicket-
7.x/lambda-parent/lambda/src/main/java/org/wicketstuff/
lambda/SerializableBiConsumer.java
WBR, Maxim
(from mobile, sorry for the typos)
Post by Maxim Solodovnik
https://cwiki.apache.org/confluence/display/WICKET/
Migration+to+Wicket+8.0#MigrationtoWicket8.0-
Provideserializableversionsofjava.util.function.(Supplier|
Consumer|Function|BiConsumer)ASFJIRA5aa69414-a9e9-3523-
82ec-879b028fb15bWICKET-5991
Post by Maxim Solodovnik
<https://cwiki.apache.org/confluence/display/WICKET/
Migration+to+Wicket+8.0#MigrationtoWicket8.0-
Provideserializableversionsofjava.util.function.(Supplier%
7CConsumer%7CFunction%7CBiConsumer)ASFJIRA5aa69414-a9e9-3523-82ec-
879b028fb15bWICKET-5991>
Post by Maxim Solodovnik
WBR, Maxim
(from mobile, sorry for the typos)
Post by m.xinu
Hi,
I'm using Apache Wicket 7.9.0 alongside Spring 5.0.5.RELEASE. In one of
my beans, I call some stream API containing multiple lambda expressions.
org.devocative.metis.service.data.ReportService$$Lambda$126/997816965
and it is very strange for me since it is in one of my beans not in any
Wicket-related part.
I've searched and I've found the Serializable casting solution, however
it results in a very complex syntax for my code. So is there any other
solution? Dose Wicket has a way for this type of serialization?
reports.parallelStream()
      .filter(report ->
        externalAuthorizationService == null ||
            externalAuthorizationService.authorizeReport(report, null,
currentUser.getUserId())
      )
      .flatMap(report -> report.getGroups().stream().map(dataGroup -> new
KeyValueVO<>(dataGroup, report)))
      .collect(Collectors.groupingBy(
        KeyValueVO::getKey,
        () -> new TreeMap<>(Comparator.comparing(DataGroup::getName)),
        Collectors.mapping(
            KeyValueVO::getValue,
            Collectors.toList()))
      );
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@wicket.apache.org
For additional commands, e-mail: users-***@wicket.apache.org

Loading...