Friday, June 16, 2023

Retrofit x xml

因為工作上需要,暫時得自己生假資料

然後不想做假資料,就看了一下 open data 有提供 縣市 & 鄉鎮 的 api


但給的格式是 xml, 所以研究了一下怎麼在 retrofit 裡面 parse xml


SimpleXmlConverterFactory


雖然可以用,但被列為廢棄了,再找一下發現有 大大推薦 替代方案


Tickaroo/tikxml


import 的時候有遇到一些麻煩,dependency 有些複雜,最後搞定的設定如下:

project gradle : 

//Jitpack pulls the dependencies straight from GitHub and builds them (for TikXML)
maven { url 'https://www.jitpack.io' }


app gradle :

// TikXML, xml parser
// wee need processor & processor-common to generate objectClass$$TypeAdapter
implementation 'com.github.Tickaroo.tikxml:annotation:0.8.15'
implementation 'com.github.Tickaroo.tikxml:core:0.8.15'
implementation'com.github.Tickaroo.tikxml:retrofit-converter:0.8.15'
// we need this guava to avoid Duplicate class com.google.common.util.concurrent.internal.InternalFutureFailureAccess for retrofit-converter
implementation 'com.google.guava:guava:27.0.1-android'
kapt 'com.github.Tickaroo.tikxml:processor-common:0.8.15'
kapt 'com.github.Tickaroo.tikxml:processor:0.8.15'

proguard:

# for TikXML
-keep class com.tickaroo.tikxml.** { *; }
-keep @com.tickaroo.tikxml.annotation.Xml public class *
-keep class **$$TypeAdapter { *; }

-keepclasseswithmembernames class * {
@com.tickaroo.tikxml.* <fields>;
}

-keepclasseswithmembernames class * {
@com.tickaroo.tikxml.* <methods>;
}
# end for TikXML





No comments:

Post a Comment