miggyyy
miggyyy

Reputation: 49

Constructor not matched for class

I am trying to deserialize an xml file, But I am having errors on deserializing it using the code below:

try {
    Strategy strategy = new CycleStrategy("id", "ref");
    Serializer serializer = new Persister(strategy);
    File source = new File("ActionToLettersAndBorrowers.xml");
    ProcessEngineObject op = serializer.read(ProcessEngineObject.class, source);

    System.out.println(op.getName());

} catch (Exception e) {
    e.printStackTrace();
}

Am i missing something out? I got the idea from simplexml website.

Upvotes: 2

Views: 2626

Answers (2)

Neuron
Neuron

Reputation: 1129

In Kotlin you just need to predefine your properties. Example:

@Root(name = "Response")
data class LinkResponse @JvmOverloads constructor(
@field:Element(name = "Field1")
var bucket: String = "",
@field:Element(name = "Field2")
var key: String = "",
@field:Element(name = "Field3")
var etag: String = "",
@field:Element(name = "Field4")
var location: String = ""
)

Upvotes: 2

marcolav
marcolav

Reputation: 485

You can define two constructors, like:

class Strategy {
...
    Strategy(){...}
    Strategy(String id, String ref){...}
}

Another approach could be defining a no-arg constructor and then set the properties you need.

Upvotes: 0

Related Questions