Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializing with a trailing comma #101

Open
snaffi opened this issue Jan 6, 2025 · 2 comments
Open

Serializing with a trailing comma #101

snaffi opened this issue Jan 6, 2025 · 2 comments
Assignees
Labels
confirmed Seen by me, feature confirmed, or issue acknowledged

Comments

@snaffi
Copy link

snaffi commented Jan 6, 2025

Hello Jairus

Thank you for amazing library 🔥

Unfortunatelly I reproduced trailing comma issue .

import {JSON} from "json-as";

@json
export class ItemPluginsBasket {
    @alias("catalog_id")
    catalogId!: string;
    @alias("catalog_item_id")
    catalogItemId!: string;
    @alias("outlet_id")
    outletId!: string;
}

@json
export class ItemPlugins {
    @omitnull()
    basket!: ItemPluginsBasket | null;
}

@json
export class Item {
    id!: string;
    @omitnull()
    plugins!: ItemPlugins | null;
}

export function example(): void {
    const s: Item = {
        id: "1",
        plugins: {
            basket: {
                catalogId: "1",
                catalogItemId: "2",
                outletId: "3"
            }
        }
    };
    const outputStr = JSON.stringify<Item>(s);

    console.log(outputStr);
}

Output

{"id":"1","plugins":{"basket":{"catalog_id":"1","catalog_item_id":"2","outlet_id":"3"},}}

If I add some dummy property it produces valid json

@json
export class EmptyObject {
}

@json
export class ItemPlugins {
    @omitnull()
    basket!: ItemPluginsBasket | null;

    dummy!: EmptyObject | null; 
}

Related to #26

@JairusSW
Copy link
Owner

JairusSW commented Jan 7, 2025

@snaffl, thanks you! I'll fix this in a moment. Either in the upcoming v1.0 release or a patch release

@JairusSW
Copy link
Owner

JairusSW commented Jan 7, 2025

Also sorry I forgot about your previous issue, I didn't mean to close it

@JairusSW JairusSW reopened this Jan 7, 2025
@JairusSW JairusSW self-assigned this Jan 8, 2025
@JairusSW JairusSW added the confirmed Seen by me, feature confirmed, or issue acknowledged label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed Seen by me, feature confirmed, or issue acknowledged
Projects
None yet
Development

No branches or pull requests

2 participants