XStream

Protected empty constructor should be valid for JavaBeanConverter

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.3
  • Component/s: None
  • Labels:
    None

Description

I spent quite some time trying and failing to get the JavaBeanConverter working until I realised that an empty constructor is required and needs to be public. Otherwise things default back to field based serialization. This is not ideal, my domain objects have empty protected constructors which work nicely with Hibernate getter/setter serialization for example.

Activity

Hide
Damon Rand added a comment -

I think JBC needs two changes to be as useful as field conversion.

  • It would have to be able to deal with any visibility on both constructors and getters/setters.
  • It would need some way of marking a visible get/set pair as "do not (de)serialize" – the equivalent of the transient tag for field serialization.
Show
Damon Rand added a comment - I think JBC needs two changes to be as useful as field conversion.
  • It would have to be able to deal with any visibility on both constructors and getters/setters.
  • It would need some way of marking a visible get/set pair as "do not (de)serialize" – the equivalent of the transient tag for field serialization.
Hide
Guilherme Silveira added a comment -

Java 2 definition on javabeans oblies the public constructor with no args:
http://java.sun.com/developer/onlineTraining/Beans/JBeansAPI/shortcourse.html

Nevertheless its possible to create support for protected or any other no-args constructor, but that would make many objects a JavaBean even tough they are not, for example java.util.ArrayList would seem to be a javabean when it does not have the desired get/set standard that would allow it to be correctly converted. It would be impossible to foresee which classes with no-args constructors are javabeans and which one's aren't.

Show
Guilherme Silveira added a comment - Java 2 definition on javabeans oblies the public constructor with no args: http://java.sun.com/developer/onlineTraining/Beans/JBeansAPI/shortcourse.html Nevertheless its possible to create support for protected or any other no-args constructor, but that would make many objects a JavaBean even tough they are not, for example java.util.ArrayList would seem to be a javabean when it does not have the desired get/set standard that would allow it to be correctly converted. It would be impossible to foresee which classes with no-args constructors are javabeans and which one's aren't.
Hide
Joerg Schaible added a comment -

The next release will allow you to use a JavaBeanConverter with a customized BeanProvider. Simply overwrite the getDefaultConstructor method and you may also return a protected one. However, it will be not implemented by default.

Show
Joerg Schaible added a comment - The next release will allow you to use a JavaBeanConverter with a customized BeanProvider. Simply overwrite the getDefaultConstructor method and you may also return a protected one. However, it will be not implemented by default.
Hide
Joerg Schaible added a comment -

Closing issues before next release.

Show
Joerg Schaible added a comment - Closing issues before next release.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: