Skip to content

Commit

Permalink
[java] fixed reading array parameters in the CDP client
Browse files Browse the repository at this point in the history
  • Loading branch information
joerg1985 committed Nov 9, 2023
1 parent d1787a9 commit feece00
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
18 changes: 16 additions & 2 deletions java/src/org/openqa/selenium/devtools/CdpClientGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -439,14 +439,22 @@ public BodyDeclaration<?> toMethodDeclaration() {
String.format(
"return new Event<>(\"%s.%s\", ConverterFunctions.empty());",
domain.name, name));
} else if (type instanceof ObjectType || type instanceof ArrayType) {
} else if (type instanceof ObjectType) {
methodDecl
.getBody()
.get()
.addStatement(
String.format(
"return new Event<>(\"%s.%s\", input -> %s);",
domain.name, name, type.getMapper()));
} else if (type instanceof ArrayType) {
methodDecl
.getBody()
.get()
.addStatement(
String.format(
"return new Event<>(\"%s.%s\", ConverterFunctions.map(\"%s\", input -> %s));",
domain.name, name, type.getName(), type.getMapper()));
} else {
methodDecl
.getBody()
Expand Down Expand Up @@ -660,11 +668,17 @@ public MethodDeclaration toMethodDeclaration() {
body.addStatement(
String.format(
"return new Command<>(\"%s.%s\", Map.copyOf(params));", domain.name, name));
} else if (type instanceof ObjectType || type instanceof ArrayType) {
} else if (type instanceof ObjectType) {
body.addStatement(
String.format(
"return new Command<>(\"%s.%s\", Map.copyOf(params), input -> %s);",
domain.name, name, type.getMapper()));
} else if (type instanceof ArrayType) {
body.addStatement(
String.format(
"return new Command<>(\"%s.%s\", Map.copyOf(params), ConverterFunctions.map(\"%s\","
+ " input -> %s));",
domain.name, name, type.getName(), type.getMapper()));
} else {
body.addStatement(
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,21 @@ public static <X> Function<JsonInput, X> map(final String keyName, Type typeOfX)
Require.nonNull("Key name", keyName);
Require.nonNull("Type to convert to", typeOfX);

return map(keyName, input -> input.read(typeOfX));
}

public static <X> Function<JsonInput, X> map(final String keyName, Function<JsonInput, X> read) {
Require.nonNull("Key name", keyName);
Require.nonNull("Read callback", read);

return input -> {
X value = null;

input.beginObject();
while (input.hasNext()) {
String name = input.nextName();
if (keyName.equals(name)) {
value = input.read(typeOfX);
value = read.apply(input);
} else {
input.skipValue();
}
Expand Down

0 comments on commit feece00

Please sign in to comment.