Re: [Simple-support] Transform annotations, simple class names, JSON output, and more
Brought to you by:
niallg
|
From: Robbie B. <Rob...@sa...> - 2014-02-12 15:27:48
|
You can use Gson with SimpleXML. It doesn’t care about the SimpleXML annotations:
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Root;
import com.google.gson.Gson;
public class SimpleXMLtoJSONtest {
@Root
public static class A {
@Attribute
private int x;
public A() {
}
public A(int x) {
this.x = x;
}
}
public static void main(String... args) {
A a = new A(5);
Gson gson = new Gson();
System.out.println(gson.toJson(a));
}
}
—Robbie
From: Paul Johnston <pa...@pa...<mailto:pa...@pa...>>
Date: Wednesday, February 12, 2014 at 8:50 AM
To: "sim...@li...<mailto:sim...@li...>" <sim...@li...<mailto:sim...@li...>>
Subject: Re: [Simple-support] Transform annotations, simple class names, JSON output, and more
Hi,
I am now able to answer some of my own questions:
1) Can I strip the value element on an ElementMap?
I couldn't find a way to do this, but I modified OutputElement.getChild to add this:
if(name.equals("<SKIP>"))
return this;
I realise this is a bit of a hack, but it does what I need. A proper way of doing this would be appreciated.
2) Can Simple generate short names in class attributes?
I have done this by subclassing TreeStrategy.
3) Can I specify Transformers using an annotation?
At the moment the answer is no. Potentially this could be done, in a similar way to how Converter is done at the moment. But this isn't particularly important to me.
4) Can Simple generate JSON output?
No progress on this just yet.
Is anyone out there? Just a quick mail letting me know the list is alive would be appreciated :-)
Paul
|