This is script that uses java classes generated by wsimport tool and based on them generates Kotlin classes with TikXml annotations.
wsimport is part of Java SDK, it is included also in Java provided with AndroidStudio in android-studio\jre\bin\wsimport
Generated Kotlin classes are intended to be used with TikXml Annotation processor.
This script also generates extensions for TikXml.Builder
to add any needed TypeAdapter
s.
If given WSDL contain any types that require adapters, there will be TikXmlAdapters.kt
file alongside models. It have extension addEnumAdapters()
to include all needed type adapters.
Remember to add your own Date
TypeConverter if needed (there will be info when processing classes about that).
First we need to run wsimport tool to generate java classes. For this example we will create models into com.example.model
package.
wsimport -keep -p com.example.model -s java_gen -d temp {wsdl_link}
explanation:
-keep
instructs tool to do not remove generated java code (by default it compiles them and only leave.class
files).-p {package}
this will make classes be generated in proper java package also creating whole directory structure.-s {dir_name}
root directory where java source code structure will be generated into. Directory must exist before running the tool.-d {dir_name}
root directory where tool will compile java classes into. Directory must exist before running the tool. This directory can be removed afterwards.
After classes are generated just run this script passing directory from -s
option as an argument:
javaSoap2kotlinTikxml.sh java_gen
This will mirror directory structure to java_gen_kt
({dir_name}_kt
) with Kotlin classes.
Now you just need to use provided extension function when creating TikXml instance like so:
TikXml.Builder()
.addModelAdapters() //<-- this is the generated extension that will add all needed Adapters
// if there was an info about dates, please also add here the converter for Date class
.build()
Please note that I have only tried it on Windows running wsimport from batch script and then running this script from Cygwin.