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 객체를 만드는데 주의해야할 듯 싶다.
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 객체를 만드는데 주의해야할 듯 싶다.
'Android' 카테고리의 다른 글
개발자 모드가 ON 되어 있는지 확인 (0) | 2017.12.14 |
---|---|
app:transformResourcesWithMergeJavaResForDebug library release.kotlin_module (0) | 2017.12.11 |
gradle 로 다운로드 받은 라이브러리 경로 (download path) (0) | 2017.11.27 |
kotlin and SAM (0) | 2017.11.24 |
android build tool 3.x issue (0) | 2017.11.03 |