falkreon / Jankson

JSON5 / HJSON parser and preprocessor which preserves ordering and comments
MIT License
51 stars 9 forks source link

Verify that JsonPrimitive constructor is called with a value type that makes sense #28

Closed Barteks2x closed 4 years ago

Barteks2x commented 5 years ago

Currently, accidentally calling JsonPrimitive constructor with a wrong type (like String[]) can result in weird issues that show up much later in the code. Failing early would be much more useful in that case.

falkreon commented 4 years ago

This is partly done now; I added typed factory methods (like JsonPrimitive.of(8)) and now warn in the javadocs that the bare new JsonPrimitive(Object) may trigger expensive checks. I find that in all of my circumstances method polymorphism can do those checks for free, so I can safely spend some time in that constructor and make this happen.