10
10
import elemental .json .JsonValue ;
11
11
import org .apache .commons .lang3 .StringUtils ;
12
12
13
+ import java .util .Base64 ;
14
+
13
15
import static java .util .Arrays .stream ;
14
16
15
17
public class VElement {
@@ -74,10 +76,16 @@ public <T> Registration on(Class<T> eventType, SerializableConsumer<T> listener)
74
76
75
77
/**
76
78
* 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>
79
85
*
86
+ * <p>
80
87
* On the client side, the event should be dispatched with a CustomEvent with the detail property.
88
+ * </p>
81
89
*
82
90
* @param eventName the name of the event
83
91
* @param eventType the DTO of the "event.detail"
@@ -97,6 +105,8 @@ public <T> Registration on(String eventName, Class<T> eventType, SerializableCon
97
105
value = (T ) Double .valueOf (jsonValue .asNumber ());
98
106
} else if (eventType == Boolean .class ) {
99
107
value = (T ) Boolean .valueOf (jsonValue .asBoolean ());
108
+ } else if (eventType == byte [].class ) {
109
+ value = (T ) Base64 .getDecoder ().decode (jsonValue .asString ());
100
110
} else if (jsonValue .getType () == JsonType .OBJECT ) {
101
111
try {
102
112
value = objectMapper .readValue (jsonValue .toJson (), eventType );
0 commit comments