com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$DuplicateFieldException: Duplicate field

StackOverflow https://stackoverflow.com/questions/21307117

  •  01-10-2022
  •  | 
  •  

Question

field               : param
class               : xmleditor.domain.Type
required-type       : xmleditor.domain.Type
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path                : /root/type/param[2]

I get this Error that I got duplicate Param. But when I try to Use

xstream.addImplicitCollection

I get this error :

Exception in thread "main" com.thoughtworks.xstream.InitializationException: Field "param" declares no collection or array.

So I dont know what is my problem really.

 @XStreamAlias("root")
    public class Type {

        private Info info;
        @XStreamAlias("OBJECT_TYPE")
        private String objectType;
        private Properties prop;
        private Parameters param;
        private Restrictions restri;

        @XStreamImplicit(itemFieldName = "type")
        private List typeList = new ArrayList();
// Constructor, Getters and setters.

What could be the cause of this problem?

Was it helpful?

Solution

Declaring an implicit collection means that you have several xml-elements with the same tag name at the same nesting level in your xml document.

To map these to your Java classes, you need either a Collection or an Array to store those objects in. XStream can handle this by mapping those elements as an implicit collection to your object structure.

Thus you need to change the param variable to a Collection or Array type. That is, change

from:

private Parameters param;

to:

@XStreamImplicit
private List<Parameters> param;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top