Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullable Types and Non Nullable Default Value Strategy #391

Closed
ArcherEmiya05 opened this issue May 7, 2022 · 2 comments
Closed

Nullable Types and Non Nullable Default Value Strategy #391

ArcherEmiya05 opened this issue May 7, 2022 · 2 comments
Assignees
Labels
bug L3 Difficulty level 3 (Maximum is 9)

Comments

@ArcherEmiya05
Copy link

ArcherEmiya05 commented May 7, 2022

Looking at this settings, I get a little confuse about what will happen if the type is nullable base from the JSON itself but setting the default value strategy as non null? Is the type becomes nullable or non null

image

@ArcherEmiya05
Copy link
Author

ArcherEmiya05 commented May 7, 2022

It became nullable Any? I am expecting nullable String

Sample

"links": [
                {
                    "url": null,
                    "label": "« Previous",
                    "active": false
                },
                {
                    "url": "http://localhost:8000/api/active-announcements?page=1",
                    "label": "1",
                    "active": true
                },
                {
                    "url": "http://localhost:8000/api/active-announcements?page=2",
                    "label": "2",
                    "active": false
                },
                {
                    "url": "http://localhost:8000/api/active-announcements?page=3",
                    "label": "3",
                    "active": false
                },
      ]
@JsonClass(generateAdapter = true)
data class Link(
    @Json(name = "active")
    val active: Boolean = false,
    @Json(name = "label")
    val label: String = "",
    @Json(name = "url")
    val url: Any? = Any()
)

@ArcherEmiya05 ArcherEmiya05 changed the title Question: About Types and Default Value Strategy Nullable Types and Non Nullable Default Value Strategy May 7, 2022
@wuseal
Copy link
Owner

wuseal commented May 11, 2022

Looking at this settings, I get a little confuse about what will happen if the type is nullable base from the JSON itself but setting the default value strategy as non null? Is the type becomes nullable or non null

The type will be nullable if the json value is null, and will be non-nullable if the json value never be null

For your case, it seems there are some bugs, will fix it next version.

Thank you for your feedback

@wuseal wuseal added bug L3 Difficulty level 3 (Maximum is 9) labels May 11, 2022
@wuseal wuseal self-assigned this May 11, 2022
@wuseal wuseal closed this as completed in 9e6a0dc May 17, 2022
wuseal added a commit that referenced this issue May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug L3 Difficulty level 3 (Maximum is 9)
Projects
None yet
Development

No branches or pull requests

2 participants