How can I create a descriptor for a Json list alwa...
# serialization
l
How can I create a descriptor for a Json list always containing a single element?
I.e. for a
Copy code
["example"]
a
It sounds like a you want a tuple? Try looking at this issue https://github.com/Kotlin/kotlinx.serialization/issues/1906
l
Well yeah, of one.
Problem: I have two classes,
Functional
(a tuple of one), and
Primitive
(converts
{ "@value": "etc" }
to
"etc"
). However, when using
Functional<Primitive<String>>
, I get the following error:
Copy code
kotlinx.serialization.json.internal.JsonDecodingException: Expected class kotlinx.serialization.json.JsonObject as the serialized body of quest.laxla.khuzdul.Primitive, but had class kotlinx.serialization.json.JsonArray
The purpose is to convert
[{"@value": "etc"}]
to
"etc"
so eh
ouch
alright now both work on their own but it still doesn't work together??
ah wait iky
It's cause they're inline
That... probably shouldn't be a feature
I'm so confused
Copy code
Expected class kotlinx.serialization.json.JsonObject as the serialized body of quest.laxla.khuzdul.Primitive, but had class kotlinx.serialization.json.JsonArray
It still doesn't work??
a
encoder.encodeStructure
along with
encoder.encodeSerializableValue
looks suspect to me
l
hmmmm?
Then what should I replace them with?
a
Typically I'd use
encoder.encodeStructure
to do everything manually.... that is to say, I don't use it because doing it manually is a hassle :)
l
ohhhhh ic thanks
a
instead of doing
encodeSerializableValue
inside of
encodeStructure
, I think there will be an
encodeElement(...)
instead?
l
So this should work, right?
a
run the code and you tell me 😀
l
nope it doesn;t
This works
a
hmmm
encodeSerializableElement
should use the descriptor of the value, not the descriptor of your Functional/Primitive Serializers?
l
idk, cause I already give it the serializer
(of the value)
But serializing to this doesn't
@Adam S neither work
Primitive is now implemented like this cause I'm stupid
GOD
I fixed functional's deserializer which apparently didn't work well
but it still doesn't work