Refine *HttpMessageConverter#getContentLength
return value null safety
#32325
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
status: backported
An issue that has been backported to maintenance branches
theme: kotlin
An issue related to Kotlin support
type: enhancement
A general enhancement
Milestone
id("org.springframework.boot") version "2.3.9.RELEASE"
I need to extend MappingJackson2HttpMessageConverter and override getContentLength
override
fun getContentLength(obj:Any, contentType:MediaType?) : Long?
Compile error:
Return type of 'getContentLength' is not a subtype of the return type of the overridden member 'protected/protected and package/ open fun getContentLength(p0: Any, @nullable p1: MediaType?): Long defined in org.springframework.http.converter.json.MappingJackson2HttpMessageConverter'
If the return type is Long, it will get NullPointException at runtime.
override
fun getContentLength(obj:Any, contentType:MediaType?) : Long
In AbstractJackson2HttpMessageConverter the return is not Nullable
@OverRide
protected Long getContentLength(Object object, @nullable MediaType contentType)
In AbstractHttpMessageConverter the return is Nullable
@nullable
protected Long getContentLength(T t, @nullable MediaType contentType)
The text was updated successfully, but these errors were encountered: