j2s: Unable to set default value of true on booleans #3

Closed
opened 2023-09-05 15:58:39 -04:00 by jordan · 4 comments
Owner

Because of the way the generated code works, we can't reliably default a boolean value to true, because both explicitly setting it and leaving it omitted in the JSON will cause the struct value to be false; we can't tell which occurred.

Because of the way the generated code works, we can't reliably default a boolean value to true, because both explicitly setting it and leaving it omitted in the JSON will cause the struct value to be false; we can't tell which occurred.
jordan added the
enhancement
label 2023-09-05 15:58:39 -04:00
Author
Owner

We could just set boolean fields to -1 when they aren't specified. Then higher-level code can set the appropriate value from there, but buggy code may blindly check the boolean and see that -1 evaluates to true and thus behave in an unexpected manner.

The other solution is to add support for setting default values at the parser level.

We could just set boolean fields to `-1` when they aren't specified. Then higher-level code can set the appropriate value from there, but buggy code may blindly check the boolean and see that `-1` evaluates to true and thus behave in an unexpected manner. The other solution is to add support for setting default values at the parser level.
jordan added this to the (deleted) milestone 2023-09-05 16:16:58 -04:00
jordan added this to the Telodendria v1.7.0-alpha4 project 2023-09-05 16:18:04 -04:00
Contributor

The other solution is to add support for setting default values at the parser level.

I think that would be the better solution here(removing non-generated initialization code for example).

> The other solution is to add support for setting default values at the parser level. I think that would be the better solution here(removing non-generated initialization code for example).
Author
Owner

Yeah, I think I agree, that's just going to be a bit more work. Figuring out how to create default objects, for example, will not be trivial.

Yeah, I think I agree, that's just going to be a bit more work. Figuring out how to create default objects, for example, will not be trivial.
Author
Owner
Moved to Telodendria/Cytoplasm#26.
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Telodendria/Telodendria#3
No description provided.