Hi Jörg , I'm using this code:
XStream xsJson = new XStream(
new JsonHierarchicalStreamDriver() {
@Override
public HierarchicalStreamWriter createWriter(Writer
writer) {
return new JsonWriter(writer,
JsonWriter.DROP_ROOT_MODE, new JsonWriter.Format(
new char[0],
new char[0],
JsonWriter.Format.SPACE_AFTER_LABEL |
JsonWriter.Format.COMPACT_EMPTY_ELEMENT
));
}
});
xsJson.setMode(XStream.ID_REFERENCES);
I'm using ID references, because on client I've a JsSerializer to convert it to
the real reference.
I'm using REST, and to convert from JSON to Java I'm using Jackson. And to
convert from Java to Json Xstream.
This proces is working well, inspect of this case, when I'm using generics
inside a pojo.
This is the test code:
ResultBean<List<GnNode>> nodos = new ResultBean<>();
ResultList<List<GnNode>> nodose = new ResultList<List<GnNode>> ();
GnNode nodo1 = new GnNode();
nodo1.setNodeId(1);
nodo1.setNodeTitle("nodo 1");
GnNode nodo2 = new GnNode();
nodo2.setNodeId(2);
nodo2.setNodeTitle("nodo 2");
List<GnNode> nodosl = new ArrayList<>();
nodosl.add(nodo1);
nodosl.add(nodo2);
nodos.setBean(nodosl);
// This code fails to return a well formed json
System.out.println("Nodos :" + xsJson.toXML(nodos));
// This code works ok, because the specification of ResultList : public
class ResultList <E> implements Serializable{ private List<E> lista = new
ArrayList<E>();
System.out.println("Nodos 2:"+xsJson.toXML(nodosl));
Lot of thanks,
Marcial
On 20/03/12 10:34, Jörg Schaible wrote:
Hi Marcial,
Atienzar Navarro, Marcial wrote:
Hi,
I've post this issue:
https://jira.codehaus.org/browse/XSTR-696
But I don't know if this is an issue or something that I'm
doing
wrong. I think that it is an issue, and for that I've
create the jira
issue.
I've a generic pojo, ResulBean<E extends Serializable> that
has a
property, E bean. When E is an ArrayList<GnNode> the output
is
something like this:
{"@id": "1","bean":
{"@class": "list","@id": "2",
"org.kyrian.entity.gnomo.GnNode": {"@id": "3","nodeId":
1,"nodeTitle":
"nodo 1"}, "org.kyrian.entity.gnomo.GnNode": {"@id":
"4","nodeId":
2,"nodeTitle": "nodo 2"} }
}
But I think the output must be something like this:
bean:[
{"@id": "3","nodeId": 1,"nodeTitle": "nodo 1"},
{"@id": "4","nodeId": 2,"nodeTitle": "nodo 2"}
]
I'm doing something wrong?
How do you initialize XStream and if you're using the Jettison-based
driver,
which version of Jettison? Why do you use id references? JSON cannot
handle
this and the tutorial explicitly states that you should not use
references
at all. Do you intend to deserialize these objects again for Java?
Cheers,
Jörg
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
--
Marcial Atiénzar Navarro
Analista de Sistemas de Información
Avda. Del Reial Monestir Ntra. Sra. Poblet, 20
46930-Quart de Poblet (Valencia)
Tel.: 961 849 249 (corto 1249)
Móvil: 629 201 240 (corto 44249)
Fax: 961 525 321
[email protected] <mailto:[email protected]>
www.umivale.es
www.sumaintermutual.es
________________________________
Antes de imprimir cualquier documento, asegúrese de que es necesario.
El medio ambiente está en nuestra mano.
El presente mensaje y los documentos que,en su caso, lleve anexos, pueden
contener información confidencial. Se informa a quién lo reciba por error, que
su uso no autorizado está prohibido legalmente. Comunique dicha situación por
la misma vía o telefónicamente al 902 365 012, no lo remita a terceros y
proceda a su eliminación inmediata.
<<inline: logotipo.png>>
<<inline: efqm.jpg>>
