package org.example.schema; import javax.xml.bind.JAXBElement; import javax.xml.bind.annotation.*; import javax.xml.namespace.QName; @XmlRegistry public class ObjectFactory { private final static QName _RootFoo_QNAME = new QName("http://www.example.org/schema", "foo"); private final static QName _RootBar_QNAME = new QName("http://www.example.org/schema", "bar"); public Root createRoot() { return new Root(); } @XmlElementDecl(namespace = "http://www.example.org/schema", name = "foo", scope = Root.class) public JAXBElement<String> createRootFoo(String value) { return new JAXBElement<String>(_RootFoo_QNAME, String.class, Root.class, value); } @XmlElementDecl(namespace = "http://www.example.org/schema", name = "bar", scope = Root.class) public JAXBElement<String> createRootBar(String value) { return new JAXBElement<String>(_RootBar_QNAME, String.class, Root.class, value); } }
for(int i=0;i < 5; i++){ op[i] = new Root(); // here op[i].get(); op[i].processFile(); op[i].tell(); }
Root op[] = new Root[5]; java.util.Arrays.fill(op, new Root());
package example; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Root.class); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(new Root(), System.out); } }
String str = "{\"ProfileInfoResult\":{\"joiningYear\":\"2009\"}}"; Root root = new Root(); Gson gson = new Gson(); root = gson.fromJson(str, Root.class); TextView b = new TextView(context); b.setText(root.ProfileInfoResult.joiningYear);
import javax.xml.bind.*; public class MarshalDemo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Root.class); Root root = new Root(); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(root, System.out); } }
public void representingNullAndEmptyCollections() throws Exception { JAXBContext jc = JAXBContext.newInstance(Root.class); Root root = new Root(); root.nullCollection = null; root.emptyCollection = new ArrayList<String>();// Shows a Empty Element root.populatedCollection = new ArrayList<String>(); root.populatedCollection.add("foo"); root.populatedCollection.add("bar"); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(root, System.out); }
import java.util.*; import javax.xml.bind.*; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Root.class); Root root = new Root(); root.defaultTimeZone = Calendar.getInstance(); root.setTimeZone = Calendar.getInstance(); root.setTimeZone.setTimeZone(TimeZone.getTimeZone("GMT")); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(root, System.out); } }
function Root(){} Root.prototype.fromRoot = function() { console.log("I'm on Root's prototype."); }; function Child(){} Child.prototype = new Root(); Child.prototype.fromChild = function() { console.log("I'm on Child's prototype."); }; var r = new Root(); var c = new Child(); r.fromRoot(); // works c.fromRoot(); // works c.fromChild(); // works r.fromChild(); // fails
Root root = new Root(); root.a = 1; root.b = 2; root.d = 3; XStream xStream = new XStream(); xStream.registerConverter(new SimpleConverter()); System.out.println(xStream.toXML(root)); Root root1 = (Root) xStream.fromXML(xStream.toXML(root));
import javax.xml.bind.*; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Root.class); Root root = new Root(); root.getClasses().add(new Class1()); root.getClasses().add(new Class2()); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(root, System.out); } }
import java.util.Date; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Root.class); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); Root root = new Root(); marshaller.marshal(root, System.out); root.setDate(new Date()); marshaller.marshal(root, System.out); } }
Root root = new Root(); root.setMain(CREATE_AND_SET_AN_INSTANCE_OF_MAIN); root.setClientList(CREATE_AND_SET_A_LIST_OF_CLIENTS); String filePath = "PATH_TO_SAVE_YOUR_FILE"; File file = new File(filePath); JAXBContext jaxbContext = JAXBContext.newInstance(Root.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(alpha, file);
import javax.xml.bind.*; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Root.class); Root root = new Root(); root.setFoo("Hello\rWorld"); root.setBar("Hello\nWorld"); Marshaller marshaller = jc.createMarshaller(); marshaller.marshal(root, System.out); } }
import javax.xml.bind.*; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Root.class); Root root = new Root(); root.setFoo("FOO"); root.setBar("BAR"); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(root, System.out); } }
import javax.xml.bind.*; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Root.class); Root root = new Root(); root.setFoo(DatatypeConverter.parseDateTime("2013-08-02T11:50:00-04:00").getTime()); root.setBar(DatatypeConverter.parseDateTime("2013-08-02T11:50:00.123-04:00").getTime()); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(root, System.out); } }
Data data = new Data(); data.setName("Tom"); Root root = new Root(); root.setData(data); ObjectMapper mapperWithMixIn = new ObjectMapper(); mapperWithMixIn.addMixInAnnotations(Root.class, RootMixIn.class); ObjectMapper mapperDefault = new ObjectMapper(); System.out.println("With MIX-IN"); System.out.println(mapperWithMixIn.writeValueAsString(root)); System.out.println("Default"); System.out.println(mapperDefault.writeValueAsString(root));
@GET @Path("/student.srv") @Produces("application/json") public Response getStudentJson(){ DAOLayer daoLayer=new DAOLayer(); List<Student> studentsList=null; try { studentsList=daoLayer.getStudents(); } catch (SQLException e) { e.printStackTrace(); } Root root = new Root(); root.setStudent(studentsList), return Response.ok(root).build(); }