Skip to content

Conversation

@Ard2025
Copy link
Collaborator

@Ard2025 Ard2025 commented Aug 24, 2025

As discussed when introducing support for new annotations we are going to use custom annotations. This PR Replaces the recently added JsonConstructor in favour of MagicConstructor

@magiccodingman
Copy link
Owner

@Ard2025 @yueyinqiu Looks good to me, but I've been out of touch. Does this need to be added to every time? When is it required? Just need to know so I can make sure when it goes through, I have documentation updated

@yueyinqiu
Copy link
Collaborator

yueyinqiu commented Aug 25, 2025

@Ard2025 @yueyinqiu Looks good to me, but I've been out of touch. Does this need to be added to every time? When is it required? Just need to know so I can make sure when it goes through, I have documentation updated

  1. A constructor with [MagicConstructor] will be preferred.
  2. Multiple magic constructors are not allowed.
  3. If no magic constructor exists, the constructor with the fewest parameters will be used.

@magiccodingman
Copy link
Owner

Perfect thank you @yueyinqiu Let me add this to the documentation before I merge this in and make a package.

@Ard2025
Copy link
Collaborator Author

Ard2025 commented Aug 25, 2025

@yueyinqiu @magiccodingman that is almost correct. When there is no Magicconstructor it picks the constructor with the most amount of parameters. When more parameters are in the constructor, likely more properties will be initiated since with for parametered constructors the properties are not filled automaticly. This is because then it is done the values set in the constructor will be overwritten by the deserializer. The deserializer can be changed to only overwrite the value if the value is default but im not sure about the performance impact of that. This change would make it possible to only to only pass the constructor parameters that are not direct propperty setters, since now if you want to do custom logic in the constructor you would be in need to pass ALL properties into the constructor.

what would both of you think of such a change?

… passed to the constructor will get initialized
@Ard2025 Ard2025 requested a review from yueyinqiu August 25, 2025 20:07
@Ard2025
Copy link
Collaborator Author

Ard2025 commented Aug 25, 2025

@magiccodingman @yueyinqiu I need both of you to look at it again, because i have added a nice improvement for parameterized constructors. I found out it isn't much of an performance deal after all. Feel free to play around some with the Person constructors to test 😊

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants