@@ -689,31 +689,40 @@ public WsServerMsg deserialize(byte[] payload) throws IOException {
689689 }
690690
691691 private WsResponse parseWsResponse (FastJsonParser p ) throws IOException {
692+ // JSON object field order is not significant, so find the type before reading the payload.
693+ int start = p .pos ;
692694 p .expectObjectStart ();
693695 String type = null ;
694- StmtResult stmtResult = null ;
695- BatchResult batchResult = null ;
696-
697696 while (!p .checkObjectEnd ()) {
698697 String field = p .nextFieldName ();
699- switch (field ) {
700- case "type" -> type = p .nextString ();
701- case "result" -> {
702- if ("execute" .equals (type )) {
703- stmtResult = parseStmtResult (p );
704- } else if ("batch" .equals (type )) {
705- batchResult = parseBatchResult (p );
706- } else {
707- p .skipValue ();
708- }
709- }
710- default -> p .skipValue ();
698+ if ("type" .equals (field )) {
699+ type = p .nextString ();
700+ } else {
701+ p .skipValue ();
711702 }
712703 }
713-
714704 if (type == null ) {
715705 throw new IOException ("WebSocket response missing type field" );
716706 }
707+
708+ p .pos = start ;
709+ p .expectObjectStart ();
710+ StmtResult stmtResult = null ;
711+ BatchResult batchResult = null ;
712+ while (!p .checkObjectEnd ()) {
713+ String field = p .nextFieldName ();
714+ if ("result" .equals (field )) {
715+ if ("execute" .equals (type )) {
716+ stmtResult = parseStmtResult (p );
717+ } else if ("batch" .equals (type )) {
718+ batchResult = parseBatchResult (p );
719+ } else {
720+ p .skipValue ();
721+ }
722+ } else {
723+ p .skipValue ();
724+ }
725+ }
717726 return switch (type ) {
718727 case "open_stream" -> WsResponse .OpenStream .INSTANCE ;
719728 case "close_stream" -> WsResponse .CloseStream .INSTANCE ;
0 commit comments