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

Behavior with IgnorePrimitiveChecks = true #175

Open
andreas-aeschlimann opened this issue Jan 8, 2022 · 0 comments
Open

Behavior with IgnorePrimitiveChecks = true #175

andreas-aeschlimann opened this issue Jan 8, 2022 · 0 comments
Labels
question Further information is requested

Comments

@andreas-aeschlimann
Copy link
Member

andreas-aeschlimann commented Jan 8, 2022

I noticed that if we set ignorePrimitiveChecks = true, then all undefined properties are ignored as well.

Example:

JSON:

{ "testt": "Hello World" }

TYPESCRIPT:

class Test {
  @JsonProperty("test", "String") test: string = ""; 
}

Deserializing the JSON above usually results in an error (property test not found in the JSON). However, when ignorePrimitiveChecks = true, then the error is ignored.

The reason is the following: json2typescript considers a missing property undefined. undefined is a primitive property and we ignore the type. Instead, json2typescript maps the undefined value to the test property in the class.

Is this behavior to be expected? Or should we treat a missing property different?

Note again, that in case ignorePrimitiveChecks = false, which is the default, there is an exception because undefined cannot be mapped as a String.

CC: @tobiasschweizer @antal-horvath

@andreas-aeschlimann andreas-aeschlimann added the question Further information is requested label Jan 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant