Last active
August 29, 2015 14:10
-
-
Save nherbaut/18c7b3497a3d7b17106a to your computer and use it in GitHub Desktop.
demarshall with xstream with no root
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.mirlitone; | |
| import java.io.IOException; | |
| import java.io.Writer; | |
| import java.util.UUID; | |
| import javax.xml.bind.JAXBException; | |
| import org.junit.Test; | |
| import com.enseirb.telecom.s9.Task; | |
| import com.enseirb.telecom.s9.Task.Args; | |
| import com.thoughtworks.xstream.XStream; | |
| import com.thoughtworks.xstream.io.HierarchicalStreamWriter; | |
| import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver; | |
| import com.thoughtworks.xstream.io.json.JsonWriter; | |
| public class Dummy { | |
| @Test | |
| public void testAll() throws IOException, JAXBException { | |
| Task task = new Task(); | |
| task.setTask("t"); | |
| task.setRetries("retries"); | |
| task.setKwargs("kwargs..."); | |
| task.setId(UUID.randomUUID().toString()); | |
| Args args = new Args(); | |
| args.getArg().add("arg1"); | |
| args.getArg().add("arg2"); | |
| task.setArgs(args); | |
| XStream xstream = new XStream(new JsonHierarchicalStreamDriver() { | |
| public HierarchicalStreamWriter createWriter(Writer writer) { | |
| return new JsonWriter(writer, JsonWriter.DROP_ROOT_MODE); | |
| } | |
| }); | |
| System.out.println(xstream.toXML(task)); | |
| // { | |
| // "id": "0af8243a-6503-464a-9ac0-2676a05371a0", | |
| // "task": "t", | |
| // "args": { | |
| // "arg": [ | |
| // "arg1", | |
| // "arg2" | |
| // ] | |
| // }, | |
| // "kwargs": "kwargs...", | |
| // "retries": "retries" | |
| // } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ajouter
en dépendance