Skip to content

Commit

Permalink
fix: encoding list error with generic array type (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
gxcsoccer authored Jan 2, 2019
1 parent 9a2c5c5 commit ad6e892
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/primitive_type/java.util.list.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = (gen, classInfo, version) => {
gen(' let uniqueId = \'%s\'', uniqueId);
gen(' if (item && item.$class) {');
gen(' desc = item;');
gen(' const type = item.$class;');
gen(' let type = item.$class;');
gen(' if (item.isArray) {');
gen(' let arrayDepth = item.arrayDepth || 1;');
gen(' while (arrayDepth--) type = \'[\' + type;');
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"homepage": "https://github.com/alipay/sofa-hessian-node#readme",
"dependencies": {
"@protobufjs/codegen": "^2.0.4",
"debug": "^4.1.0",
"debug": "^4.1.1",
"hessian.js-1": "^1.9.0",
"utility": "^1.15.0"
},
Expand All @@ -44,8 +44,8 @@
"benchmark": "^2.1.4",
"contributors": "^0.5.1",
"egg-bin": "^4.9.0",
"egg-ci": "^1.10.0",
"eslint": "^5.9.0",
"egg-ci": "^1.11.0",
"eslint": "^5.11.1",
"eslint-config-egg": "^7.1.0",
"js-to-java": "^2.6.0",
"long": "^4.0.0"
Expand Down
30 changes: 30 additions & 0 deletions test/edge_case.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ describe('test/edge_case.test.js', () => {
],
},
},

'org.sofa.TestObjectE': {
info: {
type: 'java.util.Map',
generic: [
{ type: 'java.lang.String' },
{ type: 'java.util.List', generic: [{ type: 'java.lang.Object' }] },
],
},
},
};

[
Expand Down Expand Up @@ -89,5 +99,25 @@ describe('test/edge_case.test.js', () => {

assert.deepEqual(buf1, buf2);
});

it('generic list with array type', () => {
const obj1 = {
$class: 'org.sofa.TestObjectE',
$: {
info: {
xxxx: {
$class: 'java.util.List',
$: [{
$class: 'java.lang.String',
$: [ '11', '22' ],
isArray: true,
}],
},
},
},
};
const buf = encode(obj1, version, classMap);
console.log(buf);
});
});
});

0 comments on commit ad6e892

Please sign in to comment.