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

Simplify ServerRequestExtensions.queryParamOrNull() #31264

Closed
wants to merge 5 commits into from

Conversation

esperar
Copy link
Contributor

@esperar esperar commented Sep 18, 2023

What this PR is about is

Null value processing has been modified more concisely.


While I was looking at the implementation of ServerRequestExtensions on the webflux side of the spring framework, I think I can correct it more correlatedly by putting the default string "" in the function named queryParamOrNull() when the parameter value is null.

And instead of the CollectionUtil library, I used isNullOrEmpty() provided by the Kotlin standard library.

I've tried handling null values using the elvis operator, please check it out and merge this PR if you like it!


Before

fun ServerRequest.queryParamOrNull(name: String): String? {
	val queryParamValues = queryParams()[name]
	return if (CollectionUtils.isEmpty(queryParamValues)) {
		null
	} else {
		var value: String? = queryParamValues!![0]
		if (value == null) {
			value = ""
		}
		value
	}
}

After

fun ServerRequest.queryParamOrNull(name: String): String? {
	val queryParamValues = queryParams()[name]
	return if (queryParamValues.isNullOrEmpty()) null else queryParamValues[0] ?: ""
}

Thank you :)

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 18, 2023
@esperar esperar changed the title Update :: ServerRequestExtensions queryParamOrNull() **Update** | ServerRequestExtensions queryParamOrNull() handling null values Sep 19, 2023
@esperar esperar changed the title **Update** | ServerRequestExtensions queryParamOrNull() handling null values Update ServerRequestExtensions queryParamOrNull() handling null values Sep 19, 2023
@sbrannen sbrannen added in: web Issues in web modules (web, webmvc, webflux, websocket) theme: kotlin An issue related to Kotlin support labels Sep 19, 2023
@sbrannen sbrannen changed the title Update ServerRequestExtensions queryParamOrNull() handling null values Simplify ServerRequestExtensions.queryParamOrNull() Sep 19, 2023
@sbrannen
Copy link
Member

Hi @esperar,

Please do not "request a review" from individual team members using the GitHub feature.

Somebody in the team will get to it as soon as their schedule permits.

Thanks

@sdeleuze sdeleuze self-assigned this Sep 20, 2023
@esperar
Copy link
Contributor Author

esperar commented Sep 20, 2023

I apologize. I thought it was omitted because there was no comment after the test comment.

@sdeleuze sdeleuze added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 20, 2023
@sdeleuze sdeleuze added this to the 6.1.0-RC1 milestone Sep 20, 2023
@sdeleuze sdeleuze closed this in 6caef9b Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) theme: kotlin An issue related to Kotlin support type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants