caelum/vraptor4 — pull request #679 by jlemes (2014-07-10 07:19:46+00:00)
Title: Possibility to override XStreamBuilderImpl and default mapper

HibernateProxySerializer was removed from vraptor4 and because of visibility of some classes and attributes nowdays is not possible override this behaviour to work with that because in initialization of XStream has to pass new HibernateMapper(next) , so relaxing VRaptorXStream to be extensible and some attributes is possible to override protected methods already defined in class and change the mapper . Em fact you can do a class like :

```
@Specializes
public class HibernateXStreamBuilderImpl extends XStreamBuilderImpl {

private TypeNameExtractor extractor;

@Inject
public HibernateXStreamBuilderImpl(XStreamConverters converters,
TypeNameExtractor extractor) {
super(converters, extractor);
this.extractor = extractor;
}

@Override
public XStream configure(XStream xstream) {
xstream.registerConverter(new HibernateProxyConverter());
xstream.registerConverter(new HibernatePersistentCollectionConverter(
xstream.getMapper()));
xstream.registerConverter(new HibernatePersistentMapConverter(xstream
.getMapper()));
xstream.registerConverter(new HibernatePersistentSortedMapConverter(
xstream.getMapper()));
xstream.registerConverter(new HibernatePersistentSortedSetConverter(
xstream.getMapper()));
return super.configure(xstream);
}

@Override
public XStream xmlInstance() {
VRaptorXStream xstream = new VRaptorXStream(extractor) {
protected MapperWrapper wrapMapper(final MapperWrapper next) {
vraptorMapper = new VRaptorClassMapper(new HibernateMapper(next),
new Supplier() {
@Override
public TypeNameExtractor get() {
return extractor;
}
});
return vraptorMapper;
}
};
xstream.getVRaptorMapper().getSerializee().setRecursive(recursive);
return configure(xstream);
}
}
```

to serialize hibernate proxys in controller methods like

```
this.result.use(Results.xml()).from(daoPayment().load(payment)).serialize();
```