-
Notifications
You must be signed in to change notification settings - Fork 17
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
Only Deserializing 2 Levels Deep #9
Comments
I should also note all my objects have custom types. And that it is creating objects 3 levels deep but not creating the objects with my custom types 3 levels deep. |
Hi there, There is no limit to how deep you can go. Here are some examples you can look at: Can you provide a testcase that I can try? |
So its deserializing but its not deserializing to the custom types. And upon further inspection it looks like it is not deserializing any custom nested objects. My code looks like this: getProjectList() {
return this.http.get(this.usersURL + 'projects/' + '1' + '/limit/' + '6')
.map((response: Response) => {
const projectUserList: ProjectUser[] = ObjectMapper.deserializeArray(ProjectUser, response.json());
});
} export class ProjectUser {
@JsonProperty({name: 'id'})
id: string = undefined;
@JsonProperty({ type: Date, deserializer: DateSerializerDeserializer, serializer: DateSerializerDeserializer, name: 'created_at'})
createdAt: Date = undefined;
@JsonProperty({ type: Date, deserializer: DateSerializerDeserializer, serializer: DateSerializerDeserializer, name: 'updated_at'})
updatedAt: Date = undefined;
@JsonProperty({type: User, name: 'user'})
user: User = undefined;
@JsonProperty({type: Address, name: 'address'})
address: Address = undefined;
} export class Address {
@JsonProperty({name: 'id'})
id: string = undefined;
@JsonProperty({ type: Date, deserializer: DateSerializerDeserializer, serializer: DateSerializerDeserializer, name: 'created_at'})
createdAt: Date = undefined;
@JsonProperty({ type: Date, deserializer: DateSerializerDeserializer, serializer: DateSerializerDeserializer, name: 'updated_at'})
updatedAt: Date = undefined;
@JsonProperty({name: 'street_address_line1'})
streetAddressLine1: string = undefined;
@JsonProperty({name: 'street_address_line2'})
streetAddressLine2: string = undefined;
} When I breakpoint and look at the ProjectUser object and then at the Address object all the primitive and custom deserializer date values are deserialized properly but not the Address object underneath. It looks like the deserialize function may not be taking note of the custom type annotation. |
I also tried to pull the library and run the karma tests to make a test case but I couldn't get that running either. Can you provide some documentation on how to run the test cases in the readme? |
@shakilsiraj So stepping through a debugger it seems the reflector library is not returning the type parameter to the deserializer. |
And even more weird. Nested objects of the same type of the parent object seem to work inside. |
Ok definitely something with the Reflect library as I tried this: const stuff = Reflect.getMetadata("JsonProperty", projectUserList[0], 'createdAt'); While: const stuff = Reflect.getMetadata("JsonProperty", projectUserList[0], 'user'); So there is something up with the types annotation. |
I think it might be the same as: jf3096/json-typescript-mapper#19 But not sure how to do it with different class files. |
Hmm so changing my imports around change things, but I use the same objects in various places so not sure what to do here. |
Ex. I have 1 nested class, address instance inside person instance:
} class Person {
} Serialization Result: { id: 3, address: { id: 32 } } (Working) |
Currently I have object that are nested 3-4 levels deep. However the library is currently only serializing 2 levels deep.
Is there an option somewhere to make the library deserialize deeper?
The text was updated successfully, but these errors were encountered: