You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to deserialize my result of a specific type MyType. For some
const myJson= <MyType><any>resultJson; //resultJson comes through the server with a valid value
myVal = deserialize(MyTypeA, JSON.parse(myJson)); //myVal.a='a' myVal.b='b' and myVal.id=1
myType = new MyType(myVal.a, myVal.b);
However, when I try to instantiate my object my constructor is being called and thereafter the deserializer (via index.js) overwrites my non-annotated readonly attribute from 1 to undefined. This is through the deserialize function.
Any idea why this function overwrites my already-existing attribute?
The text was updated successfully, but these errors were encountered:
To make this a little bit more clear: The following class shall be given
export class MedaFile {
id: number; //part of JSON
title: string; //part of JSON
collection: string //not a part of JSON
constructor(id?: number, title?: string) {
this.id = id;
this.title = title;
this.collection = 'mediafiles/mediafile';
}
}
With the following json (response)
{
id: 1,
title: "logo-example.png"
}
Now, when create a MediaFile using "new": const myMediaFile = new MediaFile(response.id, response.title)
the property myMediaFile.collection will be mediafiles/mediafile
in contrast, when we use deserialize like following: const myMediaFile(MediaFile, response)
the property myMediaFile.collection will be undefined
The funny part: deserialize actually calls the constructor. When you put a console.log(this.collection) in the constructor right after it was set, it works fine but gets overwritten to undefined immediately.
I am trying to deserialize my
result
of a specific typeMyType
. For someMyTypeA
has the following structure:However, when I try to instantiate my object my constructor is being called and thereafter the deserializer (via
index.js
) overwrites my non-annotatedreadonly
attribute from1
toundefined
. This is throughthe deserialize function
.Any idea why this function overwrites my already-existing attribute?
The text was updated successfully, but these errors were encountered: