Giter VIP home page Giter VIP logo

Comments (8)

jbax avatar jbax commented on August 23, 2024

Inherited methods work. Try the following example:

public class Github_45 {

    public static abstract class Named {
        @Parsed(field = "Code")
        private String code;
        @Parsed(field = "Name")
        private String name;

        public Named(){

        }

        public String toString(){
            return code + ": " + name;
        }
    }

    public static class Department extends Named {}

    public static class Employee extends Named {}

    public static void main(String ... args){
        CsvParserSettings settings = new CsvParserSettings();
        BeanListProcessor<Employee> list = new BeanListProcessor<Employee>(Employee.class);
        settings.setRowProcessor(list);

        CsvParser parser = new CsvParser(settings);
        parser.parse(new StringReader("Code,Name\nA,B\nC,D"));

        for(Employee e : list.getBeans()){
            System.out.println(e);
        }
    }
}

You are having trouble because your classes are not public and the parser can't instantiate them.

from univocity-parsers.

manish-in-java avatar manish-in-java commented on August 23, 2024

Jeronimo, thanks for your prompt reply. I took your sample, copied it to a file and ran the code. I got:

null: null
null: null
null: null

As for my original code, I had only provided a quick sample, not the actual classes. Actual classes are all public. You can download the full sample project from http://www.filedropper.com/csv-mapping_1 and run it with Maven as mvn clean test. You will find that the tests fail with the latest version (1.5.6) as well as the one I am using (1.4.0). I am running these on a Windows 7 Professional, 64-bit machine (if that matters).

from univocity-parsers.

manish-in-java avatar manish-in-java commented on August 23, 2024

See line 75 in BeanConversionProcessor in release 1.5.6 and compare it with the code on the master branch. On the master, the code attempts to go up the class hierarchy looking for fields to parse, whereas it doesn't do that in release 1.5.6.

That explains why the released code does not pick up inherited fields. Most likely, your sample must have been run against the master, which is why it would have succeeded.

from univocity-parsers.

jbax avatar jbax commented on August 23, 2024

Thanks Manish. You are correct. Use version 2.0.0-SNAPSHOT to get this fixed. We'll release the final 2.0.0 version within a month or so.

from univocity-parsers.

manish-in-java avatar manish-in-java commented on August 23, 2024

Cool, I am grateful for having stumbled across this library. I am using it in a web app that supports uploading .xls and .csv files. The difference in performance between .xls and .csv parsing is absolutely mind-blowing, and our advanced users who upload .csv files are patently thrilled.

Is it possible for you to release an intermediate version (may be 1.5.7) with just this fix? Our CSV upload feature is currently in limited beta and users are baying to release it across the application. Getting a fix will allow us to release CSV uploads to a wider audience.

from univocity-parsers.

jbax avatar jbax commented on August 23, 2024

For more immediate needs, we offer paid support and will take care of your problem straight away.

from univocity-parsers.

manish-in-java avatar manish-in-java commented on August 23, 2024

Jeronimo, do you have a release date for 2.0.0?

from univocity-parsers.

jbax avatar jbax commented on August 23, 2024

Will be around January, 2016. We are working on a lot of stuff that integrates with univocity-parsers-2.0.0 and some development is still to be made on it.

from univocity-parsers.

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.