question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSON.stringify() in generated service fails to stringify properties of object

See original GitHub issue

Abp Version: 4.8.0 using .NET Core

emptyobj

    // CreateWadConfigDto.cs
    public class CreateWadConfigDto
    {
        [Required]
        [StringLength(WadConfig.MaxNameLength)]
        public string Name { get; set; }
    }
// Generated typescript class
export class CreateWadConfigDto implements ICreateWadConfigDto {
    name: string;

    constructor(data?: ICreateWadConfigDto) {
        if (data) {
            for (var property in data) {
                if (data.hasOwnProperty(property))
                    (<any>this)[property] = (<any>data)[property];
            }
        }
    }

    init(data?: any) {
        if (data) {
            this.name = data["name"];
        }
    }

    static fromJS(data: any): CreateWadConfigDto {
        data = typeof data === 'object' ? data : {};
        let result = new CreateWadConfigDto();
        result.init(data);
        return result;
    }

    toJSON(data?: any) {
        data = typeof data === 'object' ? data : {};
        data["name"] = this.name;
        return data; 
    }

    clone(): CreateWadConfigDto {
        const json = this.toJSON();
        let result = new CreateWadConfigDto();
        result.init(json);
        return result;
    }
}

export interface ICreateWadConfigDto {
    name: string;
}

I cannot seem to find any instance of this happening in other ABP/AN0 products nor any nswag-related projects either.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
daerogamicommented, Dec 30, 2019

@maliming Nice catch! Looks like on the ngModel in my template I capitalized the property name. That appears to have fixed the ‘unexpected’ empty result.

1reaction
malimingcommented, Dec 30, 2019

It’s strange that the name in your ICreateWadConfigDto class starts with a lowercase letter(name), while the screenshot starts with a capital letter(Name).

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

json.stringify does not process object methods
JSON.stringify() will encode values that JSON supports. Objects with values that can be objects, arrays, strings, numbers and booleans.
Read more >
JSON.stringify() - JavaScript - MDN Web Docs
The JSON.stringify() static method converts a JavaScript value to a JSON string, ... if this object is a property value, the property name ......
Read more >
Unable to use JSON.stringify() on a JSON
When trying to use JSON.stringify(), I'm getting the below error: ERROR:: Can't find method com.thingworx.types.primitives.structs.Location.toJSON(string).
Read more >
Change JSON.stringify behaviour on certain builtin objects
We accidentaly called JSON.stringify on Error instance with certain non-standard properties. These objects contained _response field, ...
Read more >
JavaScript JSON stringify() Method
This argument is used to control spacing in the final string generated using JSON.stringify() function. It can be a number or a string...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found