-
Notifications
You must be signed in to change notification settings - Fork 29
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
Cannot read property 'name' of undefined #132
Comments
Hi dude, thank you for using my lib! Let me check what happens. |
Could you send me the object you tried to deserialize please? |
I've sended in the first post. It's a json array |
You told that is the response, I thought it was the result after deserialize when there is no error. Sorry so 🥴 |
I tried your code and I can't reproduce the error... Could you tell me which version of Angular are you using? A thing that could be great is to provide me a complet example with https://stackblitz.com/. |
So i think that u can't reproduce in stackblitz because the just ocuured if i run this is my package.json
|
I'll try with your version of Angular. |
It works with 11.2... It brokes during Did you set the |
the app builded but when i do the request to recive a response it's broken. Yes i set
|
What are you using to launch the application after the build? |
Angular cli to build. after u can run using http-server or run im a real server. both case it`s broken
|
u need to install https://www.npmjs.com/package/http-server |
ur object class has all params of arary? |
I used the one you provided |
humm... So we should close this issue and later i will try to get more details about the error and send u |
Ok ok, sorry :/ |
Bump! I've got the exact same error : fun fact: code works when I comment @JsonProperty in all class attributes.
usage const returnMarqueData = (res: { data: any; }) => (
res.data).map( (marque: any) => deserialize<Marque>(marque, Marque)
);
const returnTypeData = (res: { data: any; }) => (
res.data).map( (type: any) => deserialize<Type>(type, Type)
); json payload for type and then marque [
{
"data" : {
"id": 1,
"name": "foo"
}
},
{
"data" :
{
"id": 2,
"name": "bar"
}
}
]
[
{
"data" : {
"id": 1,
"name": "john"
}
},
{
"data" :
{
"id": 2,
"name": "doer"
}
}
]
classes import { JsonProperty, Serializable } from 'typescript-json-serializer';
@Serializable()
export class Marque{
@JsonProperty({ name: 'id' })
private _id: number;
@JsonProperty({ name: 'name' })
private _name: string;
constructor(id: number, name: string) {
this._id = id;
this._name = name;
}
public get id(): number {
return this._id;
}
public set id(value: number) {
this._id = value;
}
public get name(): string {
return this._name;
}
public set name(value: string) {
this._name = value;
}
} import { JsonProperty, Serializable } from 'typescript-json-serializer';
@Serializable()
export class Type{
@JsonProperty({ name: 'id' })
private _id: number;
@JsonProperty({ name: 'name' })
private _name: string;
constructor(id: number, name: string) {
this._id = id;
this._name = name;
}
public get id(): number {
return this._id;
}
public set id(value: number) {
this._id = value;
}
public get name(): string {
return this._name;
}
public set name(value: string) {
this._name = value;
}
} tsconfig.json {
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"types": [
"node",
"jest",
"@testing-library/jest-dom"
],
"include": [
"src"
]
}
.babelrc {
"presets": [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript"
],
"plugins": [
[
"@babel/plugin-proposal-decorators",
{ "legacy": true }
],
[
"@babel/plugin-proposal-class-properties",
{ "loose": true }
],
["@babel/plugin-proposal-private-methods", { "loose": true }],
]
} |
Hi, could you try to update typescript-json-serializer to the last version 3.3.0 please? |
My bad, @GillianPerard . Found solution in this previous issue. It was related to cra not supportting reflect-metadata. I configured customize-cra as pointed in the above link. Maybe, you can add it as a default config in your lib? |
My lib is not created specifically for React so I will not add this config directly but I can create a section in the ReadMe to explain how to fix the issue. Could you provide here the code you added to make it work please 😊. |
That's fair enough. Let me do that ASAP. |
Solved it by adding |
Hey dude! I'm using your nice lib. but today i got a error where just ocurred when i run ng buil -- prod
So this bug is:
if in this class of object not have some name of JsonProperty that has in the response i got this error.
this is my class object
This is the response
So i don't have in my class this names:
CLV_FL_LIMITE_REAIS
CLV_FL_LIMITE_LITROS
CCC_CD_CLIENTE_CENTRO_CUSTO
Are there some thing to resolve this in your lib?
The text was updated successfully, but these errors were encountered: