]> source.dussan.org Git - vaadin-framework.git/commitdiff
Replace function reference with anonymous class for serialization (#12137) (#12161)
authorAnna Koskinen <Ansku@users.noreply.github.com>
Wed, 2 Dec 2020 10:21:53 +0000 (12:21 +0200)
committerGitHub <noreply@github.com>
Wed, 2 Dec 2020 10:21:53 +0000 (12:21 +0200)
Lambdas and function references do not serialize

See: https://vaadin.com/forum/thread/18462951/vaadin-8-stateful-session

Authored-by: Tatu Lund <tatu@vaadin.com>
server/src/main/java/com/vaadin/ui/components/grid/GridDragSource.java

index e6f8ed2926b96ad7baa872dc5635a9bea1f8ef06..3912326a35c3df6e34df61e858116d342e2e6003 100644 (file)
@@ -85,7 +85,26 @@ public class GridDragSource<T> extends DragSourceExtension<Grid<T>> {
         super(target);
 
         // Create drag data generator
-        dragDataGenerator = this::generateDragData;
+        dragDataGenerator = new DataGenerator<T>() {
+            /**
+             * Drag data generator. Appends drag data to row data json if generator
+             * function(s) are set by the user of this extension.
+             *
+             * @param item
+             *            Row item for data generation.
+             * @param jsonObject
+             *            Row data in json format.
+             */
+            @Override
+            public void generateData(Object item, JsonObject jsonObject) {
+                JsonObject generatedValues = Json.createObject();
+
+                generatorFunctions.forEach((type, generator) -> generatedValues
+                        .put(type, generator.apply((T) item)));
+
+                jsonObject.put(GridDragSourceState.JSONKEY_DRAG_DATA, generatedValues);
+            }
+        };
 
         // Add drag data generator to Grid
         target.getDataCommunicator().addDataGenerator(dragDataGenerator);
@@ -148,24 +167,6 @@ public class GridDragSource<T> extends DragSourceExtension<Grid<T>> {
                 .collect(Collectors.toList());
     }
 
-    /**
-     * Drag data generator. Appends drag data to row data json if generator
-     * function(s) are set by the user of this extension.
-     *
-     * @param item
-     *            Row item for data generation.
-     * @param jsonObject
-     *            Row data in json format.
-     */
-    private void generateDragData(T item, JsonObject jsonObject) {
-        JsonObject generatedValues = Json.createObject();
-
-        generatorFunctions.forEach((type, generator) -> generatedValues
-                .put(type, generator.apply(item)));
-
-        jsonObject.put(GridDragSourceState.JSONKEY_DRAG_DATA, generatedValues);
-    }
-
     /**
      * Sets a generator function for customizing drag data. The generated value
      * will be accessible using the same {@code type} as the generator is set