Skip to content

Commit feece00

Browse files
committed
[java] fixed reading array parameters in the CDP client
1 parent d1787a9 commit feece00

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

java/src/org/openqa/selenium/devtools/CdpClientGenerator.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,14 +439,22 @@ public BodyDeclaration<?> toMethodDeclaration() {
439439
String.format(
440440
"return new Event<>(\"%s.%s\", ConverterFunctions.empty());",
441441
domain.name, name));
442-
} else if (type instanceof ObjectType || type instanceof ArrayType) {
442+
} else if (type instanceof ObjectType) {
443443
methodDecl
444444
.getBody()
445445
.get()
446446
.addStatement(
447447
String.format(
448448
"return new Event<>(\"%s.%s\", input -> %s);",
449449
domain.name, name, type.getMapper()));
450+
} else if (type instanceof ArrayType) {
451+
methodDecl
452+
.getBody()
453+
.get()
454+
.addStatement(
455+
String.format(
456+
"return new Event<>(\"%s.%s\", ConverterFunctions.map(\"%s\", input -> %s));",
457+
domain.name, name, type.getName(), type.getMapper()));
450458
} else {
451459
methodDecl
452460
.getBody()
@@ -660,11 +668,17 @@ public MethodDeclaration toMethodDeclaration() {
660668
body.addStatement(
661669
String.format(
662670
"return new Command<>(\"%s.%s\", Map.copyOf(params));", domain.name, name));
663-
} else if (type instanceof ObjectType || type instanceof ArrayType) {
671+
} else if (type instanceof ObjectType) {
664672
body.addStatement(
665673
String.format(
666674
"return new Command<>(\"%s.%s\", Map.copyOf(params), input -> %s);",
667675
domain.name, name, type.getMapper()));
676+
} else if (type instanceof ArrayType) {
677+
body.addStatement(
678+
String.format(
679+
"return new Command<>(\"%s.%s\", Map.copyOf(params), ConverterFunctions.map(\"%s\","
680+
+ " input -> %s));",
681+
domain.name, name, type.getName(), type.getMapper()));
668682
} else {
669683
body.addStatement(
670684
String.format(

java/src/org/openqa/selenium/devtools/ConverterFunctions.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,21 @@ public static <X> Function<JsonInput, X> map(final String keyName, Type typeOfX)
2828
Require.nonNull("Key name", keyName);
2929
Require.nonNull("Type to convert to", typeOfX);
3030

31+
return map(keyName, input -> input.read(typeOfX));
32+
}
33+
34+
public static <X> Function<JsonInput, X> map(final String keyName, Function<JsonInput, X> read) {
35+
Require.nonNull("Key name", keyName);
36+
Require.nonNull("Read callback", read);
37+
3138
return input -> {
3239
X value = null;
3340

3441
input.beginObject();
3542
while (input.hasNext()) {
3643
String name = input.nextName();
3744
if (keyName.equals(name)) {
38-
value = input.read(typeOfX);
45+
value = read.apply(input);
3946
} else {
4047
input.skipValue();
4148
}

0 commit comments

Comments
 (0)