tianchiing / xdocreport

Automatically exported from code.google.com/p/xdocreport
0 stars 0 forks source link

Unable to generate sample json from xml file (ClassCastException) #449

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. take a project xml file (see below for small example)
2. use fr.opensagres.xdocreport.document.tools.Main.main to generate sample 
json. Alternatively, let openoffice plugin generate it during preview
3. Error occurs

What is the expected output? What do you see instead?
Proper output

What version of the product are you using? On what operating system?
1.0.4

Please provide any additional information below.

With this sample xml
<pre>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<fields templateEngineKind="Freemarker" >
    <description><![CDATA[]]></description>
    <field name="p.developers.activity.commits.commitId" list="true" imageName="" syntaxKind="">
        <description><![CDATA[]]></description>
    </field>
    <field name="p.developers.activity.lastLogin" list="true" imageName="" syntaxKind="">
        <description><![CDATA[]]></description>
    </field>
    <field name="p.developers.login" list="true" imageName="" syntaxKind="">
        <description><![CDATA[]]></description>
    </field>
    <field name="p.name" list="false" imageName="" syntaxKind="">
        <description><![CDATA[]]></description>
    </field>
</fields>
</pre>
i get this exception
<pre>
Exception in thread "main" java.lang.ClassCastException: java.util.ArrayList 
cannot be cast to java.util.Map
    at fr.opensagres.xdocreport.document.tools.json.FieldsMetadataJSONSerializer.toMap(FieldsMetadataJSONSerializer.java:133)
    at fr.opensagres.xdocreport.document.tools.json.FieldsMetadataJSONSerializer.toMap(FieldsMetadataJSONSerializer.java:91)
    at fr.opensagres.xdocreport.document.tools.json.FieldsMetadataJSONSerializer.save(FieldsMetadataJSONSerializer.java:71)
    at fr.opensagres.xdocreport.document.tools.json.FieldsMetadataJSONSerializer.save(FieldsMetadataJSONSerializer.java:65)
    at fr.opensagres.xdocreport.document.tools.json.JSONDataProviderFactory.generateDefaultData(JSONDataProviderFactory.java:57)
    at fr.opensagres.xdocreport.document.tools.DataProviderFactoryRegistry.generateDefaultData(DataProviderFactoryRegistry.java:93)
    at fr.opensagres.xdocreport.document.tools.Main.process(Main.java:196)
    at fr.opensagres.xdocreport.document.tools.Main.main(Main.java:122)
</pre>

With a far more complex document (too long for here), i get the opposite 
exception:
<pre>
Exception in thread "main" java.lang.ClassCastException: 
java.util.LinkedHashMap cannot be cast to java.util.List
    at fr.opensagres.xdocreport.document.tools.json.FieldsMetadataJSONSerializer.toMap(FieldsMetadataJSONSerializer.java:129)
    at fr.opensagres.xdocreport.document.tools.json.FieldsMetadataJSONSerializer.toMap(FieldsMetadataJSONSerializer.java:91)
    at fr.opensagres.xdocreport.document.tools.json.FieldsMetadataJSONSerializer.save(FieldsMetadataJSONSerializer.java:71)
    at fr.opensagres.xdocreport.document.tools.json.FieldsMetadataJSONSerializer.save(FieldsMetadataJSONSerializer.java:65)
    at fr.opensagres.xdocreport.document.tools.json.JSONDataProviderFactory.generateDefaultData(JSONDataProviderFactory.java:57)
    at fr.opensagres.xdocreport.document.tools.DataProviderFactoryRegistry.generateDefaultData(DataProviderFactoryRegistry.java:93)
    at fr.opensagres.xdocreport.document.tools.Main.process(Main.java:196)
    at fr.opensagres.xdocreport.document.tools.Main.main(Main.java:122)
</pre>
I think this comes from a mixup in FieldsMetadataJSONSerializer.toMap where it 
assumes that the "list" flag apply to the complete reference chain while it 
applies only to the second to last element in the xxx.yyy.zzz 

Consequences: on complex structure, it practically impossible to make a preview 
using the macro plugin.

Original issue reported on code.google.com by tch...@gmail.com on 6 Oct 2014 at 2:29

GoogleCodeExporter commented 8 years ago
As complex structure was not in our scope, we have not managed that.

Please attach a simple Java class model which causes this problem. Thank's

Original comment by angelo.z...@gmail.com on 6 Oct 2014 at 2:32

GoogleCodeExporter commented 8 years ago
Here is a java class model that presents the problem. Sorry i couldn't attach a 
small sample project, as there is a "Issue attacement storage quota exceeded" 
on this project :)
I generate xml using FieldsMetadata.saveXML and generate json using 
fr.opensagres.xdocreport.document.tools.Main
The root class is Project
fieldsMetadata.load("p", Project.class);

    public class Commit {
        private String commitId;

        public String getCommitId() {
            return commitId;
        }

        public void setCommitId(String commitId) {
            this.commitId = commitId;
        }
    }
    public class Activity{
        private Date lastLogin;
        private List<Commit> commits;
        public List<Commit> getCommits() {
            return commits;
        }
        public void setCommits(List<Commit> commits) {
            this.commits = commits;
        }
        public Date getLastLogin() {
            return lastLogin;
        }
        public void setLastLogin(Date lastLogin) {
            this.lastLogin = lastLogin;
        }
    }
    public class Developer{

        private String login;
        private Activity activity;

        public String getLogin() {
            return login;
        }
        public void setLogin(String login) {
            this.login = login;
        }
        public Activity getActivity() {
            return activity;
        }
        public void setActivity(Activity activity) {
            this.activity = activity;
        }
    }
    public class Project {
        private String name;
        private List<Developer> developers;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public List<Developer> getDevelopers() {
            return developers;
        }

        public void setDevelopers(List<Developer> developers) {
            this.developers = developers;
        }
    }

Original comment by tch...@gmail.com on 7 Oct 2014 at 11:39

GoogleCodeExporter commented 8 years ago
Ok thank's for your explanation. I will see this problem when I will find time 
-(

> "Issue attacement storage quota exceeded" 

Pascal will see this problem.

Original comment by angelo.z...@gmail.com on 7 Oct 2014 at 12:18