diesieben07 diesieben07 - 2 months ago 17
Java Question

Default values with @ProjectedPayload / ProjectingJackson2HttpMessageConverter

I am using

@ProjectedPayload
on an interface to bind a JSON request body to a proxied instance of my interface.
My interface is as follows (in Kotlin, the
val
just translates to a Java getter):

@ProjectedPayload
interface ImportServer {

val id: UUID?
val name: String?

}


Now, the
id
here is completely optional, but there is no way for me to specify that, at least as far as I can tell. If I try to access the
id
property without it being present in the request body I will receive an exception from JsonPath:
com.jayway.jsonpath.PathNotFoundException: No results for path: $['id']
. If I could configure JsonPath I could use
Option.DEFAULT_PATH_LEAF_TO_NULL
and I'd get
null
for elements that are not present. But there is no way for me to get at the JsonPath configuration, it happens locked away inside
JsonProjectingMethodInterceptorFactory
.

Is there a way for me to specify a default here? Or is there a way for me to detect if the
id
is present without accessing the
id
property in the first place?

Answer Source

That's a bug and has been fixed with DATACMNS-1145. Will be released with Ingalls SR7 and transitively with Boot 1.5.7.