Comments (7)
Thanks for reporting. Arrays are inefficient because we have to know the size of the array, which means we have to read the whole xml document and store the values somewhere temporary (i.e. in a list) to know the final size of the array and then we have to copy the values from temporary structure into array.
Therefore, we don't have plans to support arrays. But at least an error message should be displayed in that case while compiling.
Nevertheless, @PropertyElement List<String>
icon can't work. I assume you try to parse a xml like
@PropertyElement
always means read the text content like
<icon>a b c d e f</icon>
@PropertyElement List<String> icon
means: convert the String "a b c d e f"
somehow to a List<String>
. TikXml cant know what a list item separator is. This could be solved by specifying a TypeConverter
(see the docs).
To group elements into a list you have to use @Element
but you are right something like @Element List<String> days
is not supported right now. Basically because we hadn't the need for that.
I have to evaluate how this could be implemented efficiently.
A possible workaround in the meantime would be
class Day {
@TextContent day;
}
and then use @Element List<Day> days
rather then @Element List<String> days
from tikxml.
Hi, @sockeqwe
I simplified my question class definition and changed the day to Class Day.
@Xml(name="weatherForecast")
public static class WeatherForecast
{
@Element
public List<Day> days;
@Element
public List<Temperature> temperature;
}
@Xml(name="day")
public static class Day{
@TextContent
String day;
}
But I got empty string.
After a little trace, I found there might be a issue about Day$$TypeAdapter.fromXML.
public class Day$$TypeAdapter implements TypeAdapter<FourDays.Day> {
public Day$$TypeAdapter() {
}
@Override
public FourDays.Day fromXml(XmlReader reader, TikXmlConfig config) throws IOException {
FourDays.Day value = new FourDays.Day();
StringBuilder textContentBuilder = new StringBuilder();
if (reader.hasAttribute()) {
if (config.exceptionOnUnreadXml()) {
throw new IOException("Could not map the xml attribute with the name '"+reader.nextAttributeName()+"' at path "+reader.getPath()+" to java class. Have you annotated such a field in your java class to map this xml attribute? Otherwise you can turn this error message off with TikXml.Builder().exceptionOnUnreadXml(false).build().");
}
while(reader.hasAttribute()) {
reader.skipAttribute();
}
}
while (reader.hasElement() || reader.hasTextContent()) {
if (reader.hasElement()) {
if (config.exceptionOnUnreadXml()) {
throw new IOException("Could not map the xml element with the tag name '"+reader.nextElementName()+"' at path "+reader.getPath()+" to java class. Have you annotated such a field in your java class to map this xml attribute? Otherwise you can turn this error message off with TikXml.Builder().exceptionOnUnreadXml(false).build().");
}
while(reader.hasElement()) {
reader.beginElement();
reader.skipRemainingElement();
}
} else if (reader.hasTextContent()) {
if (config.exceptionOnUnreadXml()) {
throw new IOException("Could not map the xml element's text content at path '"+reader.getPath()+" to java class. Have you annotated such a field in your java class to map the xml element's text content? Otherwise you can turn this error message off with TikXml.Builder().exceptionOnUnreadXml(false).build().");
}
reader.skipTextContent();
}
}
value.day = textContentBuilder.toString();
return value;
}
@Override
public void toXml(XmlWriter writer, TikXmlConfig config, FourDays.Day value) throws IOException {
}
}
textContentBuilder
is declared but never assigned. But at last we use its value.
Should we add one line textContentBuilder.append(reader.nextTextContent());
above reader.skipTextContent();
from tikxml.
you are right, that is a bug I have introduced accidentally lately when I have changed the code generation. I will fix that right now. Thanks for your detailed feedback
from tikxml.
@sockeqwe Thanks
from tikxml.
The @TextContent
bug is fixed now in 0.6.4-SNAPSHOT
. I close this issue and will split this issue into two other issues #47 (Error message for arrays) and #46 direct support for reading List
from tikxml.
On Latest also i.e 0.8.13, Can't we use @element List directly?
from tikxml.
it is giving exception like com.tickaroo.tikxml.TypeAdapterNotFoundException: No TypeAdapter for class java.lang.String found. Expected name of the type adapter is java.lang.String$$TypeAdapter
from tikxml.
Related Issues (20)
- Not skipping <!DOCTYPE> entirely
- error: incompatible types: Object cannot be converted to RequestBody HOT 1
- How to use NameSpace HOT 1
- How to initiate the lib in kotlin HOT 1
- The Future of TikXML HOT 4
- Dynamic root tag name HOT 6
- XML not generate in defined order HOT 2
- Parsing not work HOT 3
- exception while reading rss feed HOT 7
- Type converter for inserting into database HOT 2
- Problemas de parseo con dos objetos y arraylist dentro de cada uno HELP HOT 2
- Support for generic elements
- Support for iso-8859-1 HOT 7
- No TypeAdapter for class HOT 2
- java: incompatible types: java.lang.Object cannot be converted to Book HOT 2
- Docs don't mention how to make a model class for an xml like the following HOT 3
- addTypeConverter
- Support for empty lists HOT 1
- "isXXX: String" compile error
- Plans to release 0.9.x?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tikxml.