for (ChangeLogSet<?> cs : ((RunWithSCM<?, ?>) build).getChangeSets()) { Model p = new ModelBuilder().get(cs.getClass()); p.writeTo(cs, Flavor.XML.createDataWriter(cs, w));
p.writeTo(bean,pruner,Flavor.XML.createDataWriter(bean,sw));
/** * Writes the property values of the given object to the writer. */ public void writeTo(T object, DataWriter writer) throws IOException { writeTo(object, 0, writer); }
/** * Writes the property values of the given object to the writer. */ public void writeTo(T object, DataWriter writer) throws IOException { writeTo(object,0,writer); }
/** * Writes the property values of the given object to the writer. */ public void writeTo(T object, DataWriter writer) throws IOException { writeTo(object, 0, writer); }
private void writeOne(TreePruner pruner, DataWriter dw, Object item) throws IOException { Model p = MODEL_BUILDER.get(item.getClass()); p.writeTo(item, pruner, dw); }
private void writeOne(TreePruner pruner, DataWriter dw, Object item) throws IOException { Model p = MODEL_BUILDER.get(item.getClass()); p.writeTo(item, pruner, dw); }
/** * Writes the property values of the given object to the writer. * * @param baseVisibility * This parameters controls how much data we'd be writing, * by adding bias to the sub tree cutting. * A property with {@link Exported#visibility() visibility} X will be written * if the current depth Y and baseVisibility Z satisfies {@code X + Z > Y}. * * 0 is the normal value. Positive value means writing bigger tree, * and negative value means writing smaller trees. * * @deprecated as of 1.139 */ @Deprecated public void writeTo(T object, int baseVisibility, DataWriter writer) throws IOException { writeTo(object,new ByDepth(1-baseVisibility),writer); }
/** * Writes the property values of the given object to the writer. * * @param baseVisibility * This parameters controls how much data we'd be writing, * by adding bias to the sub tree cutting. * A property with {@link Exported#visibility() visibility} X will be written * if the current depth Y and baseVisibility Z satisfies X+Z>Y. * * 0 is the normal value. Positive value means writing bigger tree, * and negative value means writing smaller trees. * * @deprecated as of 1.139 */ public void writeTo(T object, int baseVisibility, DataWriter writer) throws IOException { writeTo(object,new ByDepth(1-baseVisibility),writer); }
/** * Writes the property values of the given object to the writer. * * @param baseVisibility * This parameters controls how much data we'd be writing, * by adding bias to the sub tree cutting. * A property with {@link Exported#visibility() visibility} X will be written * if the current depth Y and baseVisibility Z satisfies {@code X + Z > Y}. * * 0 is the normal value. Positive value means writing bigger tree, * and negative value means writing smaller trees. * * @deprecated as of 1.139 */ @Deprecated public void writeTo(T object, int baseVisibility, DataWriter writer) throws IOException { writeTo(object,new ByDepth(1-baseVisibility),writer); }
private static <T> void validate(T bean, Class<T> clazz) throws Exception { Model<T> model = new ModelBuilder().get(clazz); ByteArrayOutputStream schema = new ByteArrayOutputStream(); new SchemaGenerator(model).generateSchema(new StreamResult(schema)); StringWriter xml = new StringWriter(); model.writeTo(bean, Flavor.XML.createDataWriter(bean, xml)); try { SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(new StreamSource(new ByteArrayInputStream(schema.toByteArray()))).newValidator().validate(new StreamSource(new StringReader(xml.toString()))); } catch (SAXParseException x) { fail(x + "\n" + xml + "\n" + schema); } }
private <T> String serialize(T bean, Class<T> clazz) throws IOException { StringWriter w = new StringWriter(); Model<T> model = new ModelBuilder().get(clazz); model.writeTo(bean, Flavor.XML.createDataWriter(bean, w, config)); return w.toString(); }
private <T> String serialize(T bean, Class<T> clazz) throws IOException { StringWriter w = new StringWriter(); Model<T> model = new ModelBuilder().get(clazz); model.writeTo(bean, Flavor.JSON.createDataWriter(bean, w, config)); return w.toString(); }
private <T> String write(T bean) throws IOException { StringWriter w = new StringWriter(); Model model = new ModelBuilder().get(bean.getClass()); model.writeTo(bean, new TreePruner.ByDepth(-999), Flavor.JSON.createDataWriter(bean, w, config)); return w.toString().replace('\"','\''); }
@SuppressWarnings({"unchecked", "rawtypes"}) // API design flaw prevents this from type-checking private static void assertResult(String expected, Object bean, String spec) throws Exception { Model model = new ModelBuilder().get(bean.getClass()); StringWriter w = new StringWriter(); model.writeTo(bean, new NamedPathPruner(spec), Flavor.JSON.createDataWriter(bean, w, config)); assertEquals(expected, w.toString().replace("\\\"", "").replace("\"", "")); }
@Test public void merge() throws Exception { StringWriter sw = new StringWriter(); builder.get(B.class).writeTo(b, Flavor.JSON.createDataWriter(b, sw, config)); // B.x should maskc C.x, so x should be 40 // but C.y should be printed as merged assertEquals("{'_class':'B','y':20,'z':30,'x':40}", sw.toString().replace('"','\'')); }
@Test public void skipNull() throws Exception { StringWriter sw = new StringWriter(); SomeNullProperty o = new SomeNullProperty(); builder.get(SomeNullProperty.class).writeTo(o, TreePruner.DEFAULT, Flavor.JSON.createDataWriter(o, sw, config)); assertEquals("{'_class':'SomeNullProperty','bbb':'bbb','ccc':null,'ddd':'ddd'}", sw.toString().replace('"','\'')); }
/** * y is a property from a merged object but that shouldn't be visible to {@link NamedPathPruner}. */ @Test public void merge_pathPrune() throws Exception { StringWriter sw = new StringWriter(); builder.get(B.class).writeTo(b, new NamedPathPruner("z,y"), Flavor.JSON.createDataWriter(b, sw, config)); assertEquals("{'_class':'B','y':20,'z':30}", sw.toString().replace('"','\'')); }
@Test public void testNotExportedBean() throws IOException { ExportConfig config = new ExportConfig().withFlavor(Flavor.JSON).withExportInterceptor(new ExportInterceptor1()).withSkipIfFail(true); StringWriter writer = new StringWriter(); ExportableBean b = new ExportableBean(); builder.get(ExportableBean.class).writeTo(b,Flavor.JSON.createDataWriter(b, writer, config)); Assert.assertEquals("{\"_class\":\""+ExportableBean.class.getName()+"\",\"name\":\"property1\",\"notExportedBean\":{},\"shouldBeNull\":null}", writer.toString()); }
@Test(expected = IOException.class) public void testNotExportedBeanFailing() throws IOException { ExportConfig config = new ExportConfig().withFlavor(Flavor.JSON).withExportInterceptor(new ExportInterceptor2()).withSkipIfFail(true); StringWriter writer = new StringWriter(); ExportableBean b = new ExportableBean(); builder.get(ExportableBean.class).writeTo(b,Flavor.JSON.createDataWriter(b, writer, config)); }