Comments (10)
或者这种方式
java('java.util.List',[
new User(...).__fields2java()
])
我们提倡的最佳实践是单参数. 这样能避免很多问题..
from dubbo-js.
@15168326318
试下这种方式呢.
java('java.util.List',[
java('com.xxxx.User', {
name: 'bar' ,
id:33
.....
});
])
转换时 , 如果不是翻译师生成的对象(如:list ,) 会直接把参数返回. 所以new user 会处理错误..
from dubbo-js.
@15168326318 我来定位下。
from dubbo-js.
@creasy2010 你们应该按alibaba的dubbo支持的参数来实现,他们是没限制的。 微服务dubbo不太可能按你们的限制来做的,对吧。
from dubbo-js.
@15168326318 是的,只是建议;
传任意参数都是可以调通的,但 开发体验却没那么好,就像你这个例子,我们在开发过程中需要关注hessian.js能识别的对象结构 而不是本能的写一个javascript的对象;
目前我们还没想到好的方案打通这一点?
from dubbo-js.
var combineArray = function (type, value) {
var values = null;
if (value) {
values = [];
for (var i = 0, len = value.length; i < len; i++) {
values.push(combine(type, value[i]));
}
}
return {
$class: '[' + (type.name || type),
$: values
};
};
`
values.push(combine(type, value[i]));
的时候判断一下是否有__fields2java方法有则调用不知道能否解决这个问题?
from dubbo-js.
这是 Js-to-java模块的逻辑?
from dubbo-js.
@creasy2010 是的。应该阔以哦
from dubbo-js.
你看的真仔细,, 哈哈,
确实是可以的, 而且有一个更好的位置 .放这段逻辑 .. 下面会详细说明
上次跟胡峰讨论过这件事, 我把讨论的内容和例子在这里阐明下...
转换基本类型数据示例
翻译师其实做了两件事,
- 编译时, 把java接口代码转换为typescript文件;
- 运行时, 把js对象转换为hession.js协议能识别的对象;
而此issue中一直就是围绕2讨论, 因为针对java的基本类型, 我们并没有生成转换代码,需要手工去写hession.js识别的结构;
我们可以在argumentMap 方法中写转换的逻辑 .
export const DemoProviderWrapper = {
sayHello: argumentMap,
test: argumentMap,
echo: argumentMap,
getUserInfo: argumentMap,
};
你上面的例子伪代码如下:
export const DemoProviderWrapper = {
�getUserList:(userList:Array<User>)=>{
// 注: 转换的逻辑是自动生成的
// TODO null undefinded的情况还要排除
return java('java.util.List',userList.map(user=>user.__fields2java()));
},
};
但是 遇到java多态 就变得麻烦了... 这也这是为什么现在没有做这一块...
为什么没有做
估算下. 上面的解决方案能解决97%的场景, 但碰到java多态就会被"破功"了.. 尤其是参数类型不能通过次序+类型来判断的情况 ,
@lileilei
from dubbo-js.
建议把这个场景放在demo里,一个上午老泪纵横 T T
from dubbo-js.
Related Issues (20)
- Improve documentation (Web aspect)
- Improve documentation (Node aspect) HOT 2
- Improve documentation (Node aspect) HOT 2
- Improve documentation (Node aspect) HOT 1
- Improve documentation (Web aspect) HOT 3
- Improve documentation (Web aspect) HOT 2
- Improve documentation (Web aspect) HOT 2
- Improve documentation (Web aspect) HOT 1
- Improve documentation (Web aspect) HOT 2
- I'll handle the items
- Implement Load Balance HOT 1
- Implement Traffic Routing HOT 1
- Implement Service Discovery HOT 1
- Implement Filter HOT 1
- Implement Metrics HOT 3
- Implement Tracing HOT 1
- [API Bug]: dubboNodeAdapter HOT 1
- 请问支持服务注册发现、负载均衡等服务治理能力吗? HOT 2
- 麻烦问下,这个 protoc 命令是怎么来的? 为什么我的 node_module/.bin 下面没有?
- 请问可以利用java dubbo3+版本泛化调用至【Apache Dubbo-js 4.0.0 released】提供的dubbo接口吗? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dubbo-js.