Closed AlexTrotsenko closed 6 years ago
@AlexTrotsenko I will review this shortly; apologies for two week delay...
Thank you, np with delays. Just to mention - this api only changes transformation of return values from the methods of injected Java classes, but not injection of Java object.
E.g. given:
class MapProvider {
Map provideMap() {...}
}
Then following transformation will affect only return value of MapProvider.provideMap()
, but not V8JavaAdapter.injectObject(v8, new Map())
V8JavaAdapter.setJsTransformation(v8, Map.class, javaObject -> V8ObjectUtils.toV8Array(v8, javaObject) )
I have implemented it as it's minimal functionality need for me.
If you think, that ability to "override" transformation of injected objects as well is also a good idea - then api could be changed to something like:
V8JavaAdapter.injectClass(v8, Class, JavaToJsTransformation)
On further inspection, this eerily resembles the interception API that we have already (see src/main/java/io/alicorn/v8/V8JavaClassInterceptor.java
). Can you confirm this and then re-open this if the interceptor API does not meet your needs?
@crahda thanks for info, I will check V8JavaClassInterceptor
!
@crahda I have tested suggested solution with V8JavaClassInterceptor.java
.
Indeed, I was able to achieve the goal without adding new "JsTransformation"
api.
The only thing, that I need java object during construction of JS Object in .getConstructorScriptBody()
, but not afterwards. Also onInject()
call does not work for such case: I can't create JS array when Java List is injected.
I have already created pull request with the changes - https://github.com/alicorn-systems/v8-adapter/pull/28.
by V8JavaAdapter.setJsTransformation(V8, T.class, new JavaToJsTransformation() {})