No TypeAdapter for class java.lang.String found.
mandrachek opened this issue · comments
I have XML that looks like this:
<ArrayOfNodes>
<Node>
<Entry>
<ID>13456</ID>
<Name>Bob</Name>
</Entry>
</Node>
<ArrayOfNodes>
Every <Node/> only ever has one <Entry/>, but there are multiple <Node/>s.
My model (Kotlin) looks like this:
import androidx.annotation.Keep
import com.tickaroo.tikxml.annotation.Element
import com.tickaroo.tikxml.annotation.Xml
@Keep
@Xml(name="ArrayOfNodes")
data class ArrayOfNodes( @field:Element var nodes: List<Node>? = null ) {}
@Keep
@Xml(name="Node")
data class Node ( @field:Element var entry: Entry? = null ) {}
@Keep
@Xml(name="Entry")
data class Entry(
@field:Element(name = "ID")
var id: String? = null,
@field:Element(name = "Name")
var name: String? = null
) {}
I'm using retrofit and have exceptionOnUnreadXml set to false.
I'm getting the following runtime exception:
com.tickaroo.tikxml.TypeAdapterNotFoundException: No TypeAdapter for class java.lang.String found. Expected name of the type adapter is java.lang.String$$TypeAdapter
Upon inspection of the full stack trace, it looks like my ArrayOfNodes and Nodes TypeAdapers are working properly, but as soon as the Entry$TypeAdapter tries to parse the ID, it fails - the "offending" code in the generated type adapter looks like this:
childElementBinders.put("ID", new ChildElementBinder<Entry>() {
@Override
public void fromXml(XmlReader reader, TikXmlConfig config, Entry value) throws IOException {
value.setId((String)config.getTypeAdapter(String.class).fromXml(reader, config));
}
});
It appears to be failing on the config.getTypeAdapter(String.class).
It appears I should have been using @PropertyElement for the values in the Entry.