Does the following make sense? The JSON lens is ty...
# http4k
s
Does the following make sense? The JSON lens is typed as non-nullable
X
yet gives out a
null
pointer
Copy code
public fun main() {
    val l: BiDiBodyLens<X> = Body.auto<X>().toLens()
    val request: Request = Request(POST, "/").body("null")
    val extracted: X = l.extract(request)
    print(extracted) // null :shrug:
}
d
TBH I'm not sure - which module are you using? I know for instance that GSON doesn't support nullability correctly
also - although null is a valid JSON value, it may depend on if the implementors were expecting an object or an array
s
it's format-jackson in the most recent version
IMHO, the lens shouldn't give out a null pointer anyways if it's configured as non-nullable, it's maybe not properly caught coming from a Java module somewhere?
r
Yep if you want a failing test:
Copy code
@Test
    fun jacksonNullMappingError() {
        data class TestData(val s: String)
        val l: BiDiBodyLens<TestData> = Body.auto<TestData>().toLens()
        val request: Request = Request(<http://Method.POST|Method.POST>, "/").body("null")
        val extracted: TestData = l.extract(request)
        print(extracted) // null :shrug:
        extracted shouldNot beNull()
    }
using Moshi.auto does as expected exception in lens
Copy code
body 'body' must be string
org.http4k.lens.LensFailure: body 'body' must be string
d
cool. I'll add something to the contract to try and get more info. I suspect Jackson isn't the only one that is a problem...
r
I guess all Java based one I guess it's TestData! that the extract returns that's why is null