Skip to content

Empty Xo-member is encoded wrong #45

@johannesheucher-gip

Description

@johannesheucher-gip

Having a complex member inside an XoObject which has no members by itself, creates a wrong JSON (the empty JSON has a key "" instead).

A {
}

B {
  a: A
}

Encoding B leads to

{
  a: {
    "": undefined
  }
}

Proposed Solution

In xo-utils.ts

    static copyProperty(src: Xo, dst: Xo, path: string): void {

        const xoPath = XoUtil.sanitizePath(path);

        const result = XoUtil.resolveCreate(dst, xoPath);

        const pathToCopy = (result.value || result?.unresolvedPath?.head === '') ? xoPath : result.resolvedPath.concat(result.unresolvedPath.head).join('.');

        dst.resolveAssign(pathToCopy, src.resolve(pathToCopy));

    }

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions