Git Product home page Git Product logo

Comments (7)

sockeqwe avatar sockeqwe commented on September 26, 2024

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.

fangzhzh avatar fangzhzh commented on September 26, 2024

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.

sockeqwe avatar sockeqwe commented on September 26, 2024

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.

fangzhzh avatar fangzhzh commented on September 26, 2024

@sockeqwe Thanks 😊

from tikxml.

sockeqwe avatar sockeqwe commented on September 26, 2024

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.

SindhuKonda avatar SindhuKonda commented on September 26, 2024

On Latest also i.e 0.8.13, Can't we use @element List directly?

from tikxml.

SindhuKonda avatar SindhuKonda commented on September 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.