https://kotlinlang.org logo
#compose-desktop
Title
# compose-desktop
r

Ryan Smith

03/29/2023, 2:56 PM
Hi everyone, I'm working on a Compose Desktop app that includes Retrofit and the need for XML {de,}serialization. I started down the road using simple-xml, but found out later that Retrofit's Simple XML converter is deprecated in favor of their JAXB converter. The interesting thing is that there appears to be two: jaxb and jaxb3. The former seems to be based on
javax.xml.bind
(which I think is the Oracle JAXB implementation), while the latter is based on the
Jakarta
JAXB implementation from The Eclipse Project. Are there any license or other issues with using the
jaxb
converter (and, by extension,
javax.xml.bind
)? I'd prefer the
Jakarta
-based converter, but I can't find an artifact for it on Maven. I suppose a more general question is "which is the recommended XML converter to use with Retrofit?"
j

jw

03/29/2023, 3:14 PM
You can also use kotlinx.serialization
With an XML text format
r

Ryan Smith

03/29/2023, 3:18 PM
From what I've read kotlinx serialization doesn't support XML and has no plans to. There's [this](https://github.com/pdvrieze/xmlutil), though, which the developer has said is pretty stable. Is this what you mean?
j

jw

03/29/2023, 3:18 PM
Yes
r

Ryan Smith

03/29/2023, 3:18 PM
🙄 at embedded link formatting on mobile
j

jw

03/29/2023, 3:19 PM
Someday they'll let us remove it like they do on desktop
r

Ryan Smith

03/29/2023, 3:19 PM
🤞
j

jw

03/29/2023, 3:21 PM
I don't have any examples of using it with Retrofit. I have an example with OkHttp
r

Ryan Smith

03/29/2023, 3:22 PM
That would help, I might end up using OkHttp directly anyways. This is for an XML-RPC API, and while Retrofit is working I think I'm lightly misusing it
r

Ryan Smith

03/29/2023, 3:25 PM
Thanks for sharing!
j

jw

03/29/2023, 4:14 PM
Configuring Retrofit, if you wanted, is as easy as calling asConverterFactory on the TextFormat instance (which should be XML type) and then adding it as normal, and using the models in the body or return position of an interface function
r

Ryan Smith

03/29/2023, 4:18 PM
Wow that's pretty convenient
asConverterFactory
from this dependency?
"com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0"
j

jw

03/29/2023, 4:23 PM
Yes. It's moving into Retrofit proper soon
Hopefully for the next release
r

Ryan Smith

03/29/2023, 4:24 PM
Ah, very cool
Getting a pretty hefty compile error while using
kotlinx.serialization
. Here's the short version:
Copy code
org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during IR lowering
File being compiled: /home/rsmit/repos/github/koji-buildroot-resolver/src/jvmMain/kotlin/data/net/xmlrpc/MethodCall.kt
The root cause java.lang.RuntimeException was thrown at: org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:49)
I'm going through my dependencies right now, somehow I ended up with both kotlin 1.8.0 and kotlin 1.8.10 in the mix
Update: that did not help. Thought I was able to get everything up to 1.8.10, but I think Compose Multiplatform 1.3.1 needs 1.7.10
j

jw

03/29/2023, 5:29 PM
There are versions for 1.8.0 and 1.8.10
r

Ryan Smith

03/29/2023, 5:32 PM
I thought Desktop 1.4.0 was still in alpha?
j

jw

03/29/2023, 5:33 PM
1.3.1 is for 1.8.10
1.3.0 for 1.8.0
r

Ryan Smith

03/29/2023, 5:34 PM
Dang, that's what I'm using so that's not the problem then
Side note: is there a compat matrix like this for desktop? https://developer.android.com/jetpack/androidx/releases/compose-kotlin
This table is why I said "I think ... 1.3.1 needs 1.7.10"
j

jw

03/29/2023, 5:36 PM
I look at the releases on the JB repo which each link to the corresponding AndroidX Compose compiler which then you can use that matrix with (or usually it will just say)
j

jw

03/29/2023, 5:37 PM
Even better
r

Ryan Smith

03/29/2023, 5:39 PM
Even more confused about this code gen error now, but at least I learned something in the process
Figured it out. In
XmlSerialName
one must provide a value for
namespace
and
prefix
even if they're empty strings.
@XmlSerialName("methodCall", "", "")
instead of
@XmlSerialName("methodCall")
Buried deep in the stack trace was this, which lead me there:
Copy code
ERROR_EXPR 'Stub expression for default value of namespace' type=kotlin.String
k

Kirill Grouchnikov

03/29/2023, 6:04 PM
JAXB still around? I had a session on it at javaone back in 2005 👀
j

jw

03/29/2023, 6:17 PM
It, like too many, were forced to migrate package names in the javax debacle. Otherwise still very much useful since not much has changed since 2005
k

Kirill Grouchnikov

03/29/2023, 6:19 PM
Back then there were around 20 competing xml serialization libraries. I had a benchmarking project on java.net to try and compare them
Courtesy of web archive
r

Ryan Smith

03/29/2023, 6:22 PM
I've tried out 3 just today, but I'd still wager there are far fewer than 20 stand-out XML libraries now that JSON, protobuf, et al are a lot more popular
k

Kirill Grouchnikov

03/29/2023, 6:22 PM
XStream is still around. Impressive run.
j

jw

03/29/2023, 6:23 PM
Jackson/Woodstox also a good choice today
r

Ryan Smith

03/29/2023, 6:24 PM
Jackson was next on my list to try before
kotlinx.serialization
came up
r

Ryan Smith

03/31/2023, 4:33 PM
@Konstantin Tskhovrebov - I noticed some nullable types in your data classes e.g.
link: Stirng?
but don't see any corresponding configuration for handling nulls. Are fields like
link
only
null
if they are omitted? If something like
<link>null</link>
appears in the XML?
I'm asking because in this XML-RPC APi I'm working with
nil
is a possible value, and I'm not seeing a way to configure my
XmlFormat
to handle that as
null
Looks like I got lucky and it's actually represented as
<nil/>
, which I can represent with an
object
.
11 Views