본문 바로가기

Android

value failed for JSON property bounds due to missing (therefore NULL) value for creator parameter bounds which is a non-nullable type

json 파싱을 주로 jackson 을 이용하는데 google 에 geo code 를 전달해 지역명을 얻는 부분을 kotlin 으로 포팅 하다가 다음과 같은 오류가 발생 했다.

W/System.err: com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException: Instantiation of [simple type, class net.sarangnamu.common.gps.domains.Geometry] value failed for JSON property bounds due to missing (therefore NULL) value for creator parameter bounds which is a non-nullable type
W/System.err:     at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 53, column: 10] (through reference chain: net.sarangnamu.common.gps.domains.Address["results"]->java.util.ArrayList[0]->net.sarangnamu.common.gps.domains.AddressResult["geometry"]->net.sarangnamu.common.gps.domains.Geometry["bounds"])

파싱을 위한 클래스는 아래와 같았고 크게 문제가 없어보였는데 다시 생각해보니 코틀린 특성을 무시한 코딩이라는걸 알게 되었고
@JsonIgnoreProperties(ignoreUnknown = true)
data class Geometry(
    val bounds: NorthEastSouthWest,
    val location: Location,
    val location_type: String,
    val viewport: NorthEastSouthWest
) : Serializable

다음과 같이 변경하였다.
@JsonIgnoreProperties(ignoreUnknown = true)
data class Geometry(
    val bounds: NorthEastSouthWest?,
    val location: Location,
    val location_type: String,
    val viewport: NorthEastSouthWest
) : Serializable

null 이 올수 있음을 알리는 ? 을 bounds 에 추가한 것으로 몇분간 -_ - 혼란에 빠지긴 했지만 앞으로 jackson 객체를 만드는데 주의해야할 듯 싶다.