Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
generic converter for Json -> object #VRaptor
public interface Jsonable { }
public class JsonableConverter implements Converter<Jsonable> {
private XStreamBuilder builder;
public JsonableConverter(XStreamBuilder builder) {
this.builder = builder;
public Jsonable convert(String value, Class<? extends Jsonable> type, ResourceBundle bundle) {
if (Strings.isNullOrEmpty(value)) return null;
XStream stream = builder.jsonInstance();
String json = String.format("{\"%s\" : %s}", type.getName(), value);
return stream.fromXML(json);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment