json2typescript icon indicating copy to clipboard operation
json2typescript copied to clipboard

Behavior with IgnorePrimitiveChecks = true

Open andreas-aeschlimann opened this issue 3 years ago • 0 comments

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 avatar Jan 08 '22 15:01 andreas-aeschlimann