Skip to content

Commit 1e89aab

Browse files
Elad Ben-IsraelRomainMuller
andauthored
fix(kernel): properly deserialize structs passed in byref (#554)
The deserializer mistakingly used `objectReference` instead of `isObjRef` when trying to identify this case. Test was added to verify this fix. Fixes #553 Co-authored-by: Romain Muller <rmuller@amazon.com>
1 parent 415cbdd commit 1e89aab

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

packages/jsii-kernel/lib/serialization.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,9 @@ export const SERIALIZERS: {[k: string]: Serializer} = {
298298

299299
// Similarly to other end, we might be getting a reference type where we're
300300
// expecting a value type. Accept this for now.
301-
const prevRef = objectReference(value);
302-
if (prevRef) {
301+
if (isObjRef(value)) {
303302
host.debug('Expected value type but got reference type, accepting for now (awslabs/jsii#400)');
304-
return prevRef;
303+
return host.objects.findObject(value).instance;
305304
}
306305

307306
const namedType = host.lookupType((optionalValue.type as spec.NamedTypeReference).fqn);

packages/jsii-kernel/test/test.kernel.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,14 @@ defineTest('erased base: can receive an instance of private type', async (test,
11581158
test.deepEqual(objref.result, { [api.TOKEN_REF]: 'jsii-calc.JSII417PublicBaseOfBase@10000' });
11591159
});
11601160

1161+
defineTest('deserialize a struct by reference', async (test, sandbox) => {
1162+
sandbox.callbackHandler = makeSyncCallbackHandler(() => 'xoxoxox');
1163+
const objref = sandbox.create({ fqn: 'Object', overrides: [ { property: 'field' } ] });
1164+
const consumer = sandbox.create({ fqn: 'jsii-calc.OptionalStructConsumer', args: [ objref ] });
1165+
const value = sandbox.get({ objref: consumer, property: 'fieldValue' });
1166+
test.deepEqual(value, { value: 'xoxoxox' });
1167+
});
1168+
11611169
// =================================================================================================
11621170

11631171
const testNames: { [name: string]: boolean } = { };

0 commit comments

Comments
 (0)