28
28
import java .util .concurrent .ConcurrentHashMap ;
29
29
import java .util .stream .Collectors ;
30
30
31
+ import com .fasterxml .jackson .databind .JsonNode ;
31
32
import com .fasterxml .jackson .databind .ObjectMapper ;
33
+ import com .fasterxml .jackson .databind .node .ObjectNode ;
32
34
import org .atmosphere .cpr .AtmosphereResource ;
33
35
import org .slf4j .Logger ;
34
36
import org .slf4j .LoggerFactory ;
35
37
36
38
import com .vaadin .base .devserver .stats .DevModeUsageStatistics ;
37
39
import com .vaadin .experimental .FeatureFlags ;
38
- import com .vaadin .flow .component .UI ;
39
40
import com .vaadin .flow .internal .BrowserLiveReload ;
41
+ import com .vaadin .flow .internal .JacksonUtils ;
40
42
import com .vaadin .flow .server .DevToolsToken ;
41
43
import com .vaadin .flow .server .VaadinContext ;
42
44
import com .vaadin .flow .server .communication .AtmospherePushConnection .FragmentedMessage ;
43
45
import com .vaadin .pro .licensechecker .BuildType ;
44
46
import com .vaadin .pro .licensechecker .LicenseChecker ;
45
47
import com .vaadin .pro .licensechecker .Product ;
46
48
47
- import elemental .json .Json ;
48
49
import elemental .json .JsonObject ;
49
50
50
51
/**
@@ -146,14 +147,14 @@ private DevToolsInterfaceImpl(
146
147
}
147
148
148
149
@ Override
149
- public void send (String command , JsonObject data ) {
150
- JsonObject msg = Json . createObject ();
150
+ public void send (String command , JsonNode data ) {
151
+ ObjectNode msg = JacksonUtils . createObjectNode ();
151
152
msg .put ("command" , command );
152
153
if (data != null ) {
153
- msg .put ("data" , data );
154
+ msg .set ("data" , data );
154
155
}
155
156
156
- debugWindowConnection .send (resource , msg .toJson ());
157
+ debugWindowConnection .send (resource , msg .toString ());
157
158
}
158
159
159
160
@ Override
@@ -255,35 +256,47 @@ public boolean isLiveReload(AtmosphereResource resource) {
255
256
*
256
257
* @param msg
257
258
* the message to broadcast
259
+ * @deprecated Use {@link #broadcast(ObjectNode)} instead.
258
260
*/
261
+ @ Deprecated
259
262
public void broadcast (JsonObject msg ) {
263
+ this .broadcast (JacksonUtils .readTree (msg .toJson ()));
264
+ }
265
+
266
+ /**
267
+ * Broadcasts the given message to all connected clients.
268
+ *
269
+ * @param msg
270
+ * the message to broadcast
271
+ */
272
+ public void broadcast (ObjectNode msg ) {
260
273
resources .keySet ().forEach (resourceRef -> {
261
274
AtmosphereResource resource = resourceRef .get ();
262
275
if (resource != null ) {
263
- resource .getBroadcaster ().broadcast (msg .toJson (), resource );
276
+ resource .getBroadcaster ().broadcast (msg .toString (), resource );
264
277
}
265
278
});
266
279
267
280
}
268
281
269
282
@ Override
270
283
public void reload () {
271
- JsonObject msg = Json . createObject ();
284
+ ObjectNode msg = JacksonUtils . createObjectNode ();
272
285
msg .put ("command" , "reload" );
273
286
broadcast (msg );
274
287
}
275
288
276
289
@ Override
277
290
public void refresh (boolean refreshLayouts ) {
278
- JsonObject msg = Json . createObject ();
291
+ ObjectNode msg = JacksonUtils . createObjectNode ();
279
292
msg .put ("command" , "reload" );
280
293
msg .put ("strategy" , refreshLayouts ? "full-refresh" : "refresh" );
281
294
broadcast (msg );
282
295
}
283
296
284
297
@ Override
285
298
public void update (String path , String content ) {
286
- JsonObject msg = Json . createObject ();
299
+ ObjectNode msg = JacksonUtils . createObjectNode ();
287
300
msg .put ("command" , "update" );
288
301
msg .put ("path" , path );
289
302
msg .put ("content" , content );
@@ -297,17 +310,18 @@ public void onMessage(AtmosphereResource resource, String message) {
297
310
getLogger ().debug ("Received live reload heartbeat" );
298
311
return ;
299
312
}
300
- JsonObject json = Json . parse (message );
301
- String command = json .getString ("command" );
302
- JsonObject data = json .getObject ("data" );
313
+ JsonNode json = JacksonUtils . readTree (message );
314
+ String command = json .get ("command" ). textValue ( );
315
+ JsonNode data = json .get ("data" );
303
316
if ("setFeature" .equals (command )) {
304
- FeatureFlags .get (context ).setEnabled (data .getString ("featureId" ),
305
- data .getBoolean ("enabled" ));
317
+ FeatureFlags .get (context ).setEnabled (
318
+ data .get ("featureId" ).textValue (),
319
+ data .get ("enabled" ).booleanValue ());
306
320
} else if ("reportTelemetry" .equals (command )) {
307
321
DevModeUsageStatistics .handleBrowserData (data );
308
322
} else if ("checkLicense" .equals (command )) {
309
- String name = data .getString ("name" );
310
- String version = data .getString ("version" );
323
+ String name = data .get ("name" ). textValue ( );
324
+ String version = data .get ("version" ). textValue ( );
311
325
Product product = new Product (name , version );
312
326
boolean ok ;
313
327
String errorMessage = "" ;
@@ -382,13 +396,13 @@ public void clearFragmentedMessage(AtmosphereResource resource) {
382
396
}
383
397
384
398
@ Override
385
- public void sendHmrEvent (String event , JsonObject eventData ) {
386
- JsonObject msg = Json . createObject ();
399
+ public void sendHmrEvent (String event , JsonNode eventData ) {
400
+ ObjectNode msg = JacksonUtils . createObjectNode ();
387
401
msg .put ("command" , "hmr" );
388
- JsonObject data = Json . createObject ();
389
- msg .put ("data" , data );
402
+ ObjectNode data = JacksonUtils . createObjectNode ();
403
+ msg .set ("data" , data );
390
404
data .put ("event" , event );
391
- data .put ("eventData" , eventData );
405
+ data .set ("eventData" , eventData );
392
406
broadcast (msg );
393
407
}
394
408
0 commit comments