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

Open
opened 2024-01-12 00:41:17 +00:00 by jordan · 0 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.

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.

@lda said in Telodendria/Telodendria#3:

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).

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.

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. 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. @lda said in Telodendria/Telodendria#3: > > 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). 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.
jordan added the
enhancement
help wanted
labels 2024-01-12 00:43:29 +00:00
jordan added this to the Cytoplasm v0.4.1 milestone 2024-01-12 00:43:39 +00:00
jordan self-assigned this 2024-01-12 00:43:45 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
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/Cytoplasm#26
No description provided.