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

Property with string literal type serializes as 'Object' #40

Closed
JohnWeisz opened this issue Sep 9, 2016 · 1 comment
Closed

Property with string literal type serializes as 'Object' #40

JohnWeisz opened this issue Sep 9, 2016 · 1 comment

Comments

@JohnWeisz
Copy link
Owner

JohnWeisz commented Sep 9, 2016

Properties with string literal types are serialized and deserialized as Object. This is caused by the Typescript compiler, which emits incorrect metadata information for these types. See microsoft/TypeScript#10809

For example, the following code will produce incorrect behavior if ReflectDecorators is used to automatically detect types:

@JsonObject
class Person {
    @JsonMember
    public name: "John" | "James";
}

The solution, until this is fixed by the TypeScript team, is to manually define the type setting:

@JsonObject
class Person {
    @JsonMember({ type: String })
    public name: "John" | "James";
}

This will raise a warning in the console however, indicating that the specified type does not match detected type:

@JsonMember: 'type' specified for 'Person.name' does not match detected type.

Since this otherwise potentially helpful warning only occurrs temporarily until the fix is shipped by Microsoft, no action will be done to suppress it in these cases.

@JohnWeisz JohnWeisz changed the title Property with string literal type serializes as array Property with string literal type serializes as 'Object' Sep 9, 2016
@JohnWeisz JohnWeisz added the bug label Sep 9, 2016
@JohnWeisz
Copy link
Owner Author

Fixed in microsoft/TypeScript#10809

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant