JsonToKotlinClass icon indicating copy to clipboard operation
JsonToKotlinClass copied to clipboard

Request: Add settings option to supress Any types in favour of Strings.

Open occultus73 opened this issue 4 years ago • 6 comments

The reason being I can't parcelize a data class with Any types in them.

Cheers.

occultus73 avatar Jul 09 '20 11:07 occultus73

@occultus73 Hi, Can you show some examples or demos?

wuseal avatar Jul 09 '20 13:07 wuseal

Oh it's very simple really: when the plugin is fed null json property, it cannot of course infer the data type from a null so the corresponding Kotlin property that is generated has a type of "Any"

Changing nulls to produce String instead of Any for null would only be a matter of one carefully placed IF statement somewhere, I would have thought... and a new button in settings.

occultus73 avatar Jul 10 '20 09:07 occultus73

@occultus73 Got it,But maybe null is a real object in future API response, Then May JSONObject can't cast to String, And It will broken in program,right?

wuseal avatar Jul 10 '20 09:07 wuseal

@occultus73 It's easy to achieve your goal, Just create an Extension for the plugin is OK. Change Type Any to String when Property#originJSONValue is null

wuseal avatar Jul 10 '20 09:07 wuseal

That is true. I think 9/10 instances it's a string. But then again over a very large data model that 1/10 is bound to come along.

Perhaps this setting wouldn't be so helpful after all. 😐

occultus73 avatar Jul 10 '20 10:07 occultus73

@occultus73 Haha, Welcome to create a pull request for this, It's also an acceptable option to replace Any with String when json value is nul

wuseal avatar Jul 10 '20 10:07 wuseal