Xstream no-args constructor error

luishenrique.ln picture luishenrique.ln · Mar 8, 2012 · Viewed 12.7k times · Source

I'm getting the following error when it tries to create an instance of 'Transacao'

`Error: Cannot construct br.com.cbmp.ecommerce.resposta.Transacao as it does not have a no-args constructor : Cannot construct br.com.cbmp.ecommerce.resposta.Transacao as it does not have a no-args constructor `

---- Debugging information ----

message : Cannot construct br.com.cbmp.ecommerce.resposta.Transacao as it does not have a no-args constructor 

cause-exception : com.thoughtworks.xstream.converters.reflection.ObjectAccessException 

cause-message : Cannot construct br.com.cbmp.ecommerce.resposta.Transacao as it does not have a no-args constructor `

class : br.com.cbmp.ecommerce.resposta.Transacao 

required-type : br.com.cbmp.ecommerce.resposta.Transacao 

path : /transacao

I am aware that there's a bug with XStream 1.3.1 and JDK7, but I'm currently using XStream 1.3.1 and JDK6. Any ideas why this error is still happening?

Thanks

Answer

JRL picture JRL · Oct 28, 2012

3 solutions:

  1. Provide a no-args constructor (obvious)
  2. Make this object implement Serializable.
  3. Upgrade to xstream 1.4.4*

I use solution #2 all the time.

*I verified 1.2.2 doesn't work and 1.4.4 does work, haven't tried any versions in-between