NetworkUtil { public static byte[] serialize(Network epn) throws Exception { byte[] ret=null; java.io.ByteArrayOutputStream baos=new java.io.ByteArrayOutputStream(); MAPPER.writeValue(baos, epn); ret = baos.toByteArray(); baos.close(); return (ret); } private  NetworkUtil(); static byte[] serialize(Network epn); static Network deserialize(byte[] epn);  }
@Test public void testSerializeEPN() { Network epn=new Network(); epn.setName("Test"); epn.setVersion("123456"); Subscription sub1=new Subscription(); sub1.setNodeName("N0"); sub1.setSubject("First"); epn.getSubscriptions().add(sub1); Subscription sub2=new Subscription(); sub2.setNodeName("N1"); sub2.setSubject("Second"); epn.getSubscriptions().add(sub2); Node n0=new Node(); n0.setName("N0"); epn.getNodes().add(n0); n0.setEventProcessor(new TestEventProcessor1()); n0.setPredicate(new TestPredicate1()); n0.getEventProcessor().getServices().put("testCache", new TestCacheManager()); Node n1=new Node(); n1.setName("N1"); epn.getNodes().add(n1); n1.getSourceNodes().add("N0"); TestEventProcessor2 ep2=new TestEventProcessor2(); n1.setEventProcessor(ep2); TestPredicate2 tp2=new TestPredicate2(); tp2.setSomeProperty("TestProperty"); n1.setPredicate(tp2); Node n2=new Node(); n2.setName("N2"); epn.getNodes().add(n2); n2.getSourceNodes().add("N0"); TestEventProcessor3 ep3=new TestEventProcessor3(); n2.setEventProcessor(ep3); try { byte[] b=NetworkUtil.serialize(epn); System.out.println("Serialized network="+new String(b)); } catch(Exception e) { fail("Failed to serialize: "+e); } }