Skip to content

Commit

Permalink
fix: mark DataSeriesItemSankey as customized to ensure its proper s…
Browse files Browse the repository at this point in the history
…erialization (vaadin#6216)

Without this call, the object would be serialized as an array containing
two value from `bean.getLow()` and `bean.getHigh()`, which are not
usually set on the Sankey type, so the result would be `[null, null]`,
instead of the actual JSON string expected (containing the `from`, `to`,
and `weight` keys).

The Sankey example in the IT works because it uses `setDataLabels`,
which in turn calls `makeCustomized` and then makes the instance to be
proper serialized.
  • Loading branch information
DiegoCardoso authored Apr 19, 2024
1 parent 505255e commit c67cb2c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class DataSeriesItemSankey extends DataSeriesItem {

public DataSeriesItemSankey() {
super();
makeCustomized();
}

/**
Expand All @@ -32,7 +33,7 @@ public DataSeriesItemSankey() {
* @param weight
*/
public DataSeriesItemSankey(String from, String to, Number weight) {
super();
this();
setFrom(from);
setTo(to);
setWeight(weight);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.vaadin.flow.component.charts;

import com.vaadin.flow.component.charts.model.DataSeriesItem;
import com.vaadin.flow.component.charts.model.DataSeriesItemSankey;
import org.junit.Assert;
import org.junit.Test;

import static com.vaadin.flow.component.charts.util.ChartSerialization.toJSON;

/**
* Tests for the serialization of custom data series items extending
* {@link DataSeriesItem}
*/
public class DataSeriesItemSerializationTest {
@Test
public void dataSeriesItemSankey_empty_toJSON() {
var json = toJSON(new DataSeriesItemSankey());
Assert.assertEquals("{}", json);
}

@Test
public void dataSeriesItemSankey_withValues_toJSON() {
var item = new DataSeriesItemSankey("A", "B", 1);
var json = toJSON(item);
Assert.assertEquals("{\"from\":\"A\",\"to\":\"B\",\"weight\":1}", json);
}
}

0 comments on commit c67cb2c

Please sign in to comment.