Skip to content

Commit 07c6940

Browse files
committed
byte[] support
1 parent 9ed4ee5 commit 07c6940

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/main/java/org/vaadin/addons/velocitycomponent/VElement.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import elemental.json.JsonValue;
1111
import org.apache.commons.lang3.StringUtils;
1212

13+
import java.util.Base64;
14+
1315
import static java.util.Arrays.stream;
1416

1517
public class VElement {
@@ -74,10 +76,16 @@ public <T> Registration on(Class<T> eventType, SerializableConsumer<T> listener)
7476

7577
/**
7678
* Listen to a custom client side event and receive the payload in "event.detail".
77-
* If the event type/payload is not String, Integer, Double or Boolean, it is expected to be a JSON
78-
* and deserialized to the event type using Jackson ObjectMapper.
79+
* If the event type/payload is not String, Integer, Double or Boolean. byte[] can be used
80+
* if the client side sends the data as a base64 encoded string.
81+
*<p>
82+
* Anything else is expected to be a JSON and deserialized to the event type using
83+
* Jackson ObjectMapper.
84+
*</p>
7985
*
86+
* <p>
8087
* On the client side, the event should be dispatched with a CustomEvent with the detail property.
88+
* </p>
8189
*
8290
* @param eventName the name of the event
8391
* @param eventType the DTO of the "event.detail"
@@ -97,6 +105,8 @@ public <T> Registration on(String eventName, Class<T> eventType, SerializableCon
97105
value = (T) Double.valueOf(jsonValue.asNumber());
98106
} else if(eventType == Boolean.class) {
99107
value = (T) Boolean.valueOf(jsonValue.asBoolean());
108+
} else if(eventType == byte[].class) {
109+
value = (T) Base64.getDecoder().decode(jsonValue.asString());
100110
} else if(jsonValue.getType() == JsonType.OBJECT) {
101111
try {
102112
value = objectMapper.readValue(jsonValue.toJson(), eventType);

0 commit comments

Comments
 (0)