Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed Java method overload bug, #349

Merged
merged 1 commit into from
May 20, 2020
Merged

Conversation

laiweiwei
Copy link
Contributor

e.g.

  1. Java:
method(JsonArray array); 
method(JsonObject object);
  1. JS:
java.method([ "a", "b", "c" ]);// JS Native Array can convert to Java Map, { 0 : "a", 1 : "b", 2 : "c" },
java.method({ name:"vv", age:18 })

e.g. 
1. Java: 
```
method(JsonArray array); 
method(JsonObject object);
```
2. JS:
```
java.method([ "a", "b", "c" ]);// JS Native Array can convert to Java Map, { 0 : "a", 1 : "b", 2 : "c" },
java.method({ name:"vv", age:18 })
```
@laiweiwei
Copy link
Contributor Author

laiweiwei commented May 7, 2020

before:

.targetTypeMapping(Map.class, JsonObject.class, null, JsonObject::new)

after:

.targetTypeMapping(Map.class, JsonObject.class, v -> !Value.asValue(v).hasArrayElements(), JsonObject::new)

@laiweiwei
Copy link
Contributor Author

whithout v -> !Value.asValue(v).hasArrayElements() the GraalJS will throws an error:

TypeError: execute on foreign object failed due to: Multiple applicable overloads found for method name 

@laiweiwei
Copy link
Contributor Author

oracle/graaljs#3

@@ -119,7 +119,7 @@ public ECMAEngine(Vertx vertx) {
// Ensure bytes are supported
.targetTypeMapping(Number.class, Byte.class, null, Number::byteValue)
// map native JSON Object to Vert.x JSONObject
.targetTypeMapping(Map.class, JsonObject.class, null, JsonObject::new)
.targetTypeMapping(Map.class, JsonObject.class, v -> !Value.asValue(v).hasArrayElements(), JsonObject::new)
// map native JSON Array to Vert.x JSONArray
.targetTypeMapping(List.class, JsonArray.class, null, JsonArray::new)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the same logic, this null should be the reversed assertion then?

Copy link
Contributor

@pmlopes pmlopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also have the reserve assertion for lists then?

@laiweiwei
Copy link
Contributor Author

Should we also have the reserve assertion for lists then?

No need to do that i think.

@laiweiwei
Copy link
Contributor Author

laiweiwei commented May 8, 2020

.targetTypeMapping(Map.class, JsonObject.class, null, JsonObject::new)
.targetTypeMapping(List.class, JsonArray.class, null, JsonArray::new)

Both of these 2 conditions are acceptable to the JS Native Array, therefore, for GraalJS, multiple choices are confused, the solution is to add a clear filter condition:

.targetTypeMapping(Map.class, JsonObject.class, !Value.asValue(v).hasArrayElements(), JsonObject::new)
.targetTypeMapping(List.class, JsonArray.class, null, JsonArray::new)

For Map.class, it will match both [] and {}.
But for List.class, it does not match both [] and {}.
So i dont think we should also have the reserve assertion for List.class case.

@pmlopes pmlopes merged commit 5ae6791 into reactiverse:develop May 20, 2020
@laiweiwei laiweiwei deleted the patch-1 branch November 4, 2020 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants