public void removeNews(News oldNews) throws DomainException { try { news.remove(oldNews); } catch (Exception ex) { if (ex.getCause().equals(NullPointerException.class)) throw new DomainException("Can't remove from news list null value", ex); else throw new DomainException("Can't remove from news list this value", ex); } }
public void addNews(News newNews) throws DomainException { try { news.add(newNews); } catch (Exception ex) { if (ex.getCause().equals(NullPointerException.class)) throw new DomainException("Can't add to news list null value", ex); else throw new DomainException("Can't add to news list this value", ex); } }
public void serialize(String fileName) { try { JAXBContext jc = JAXBContext.newInstance(this.getClass().getPackage().getName()); Marshaller m = jc.createMarshaller(); m.marshal(this, new FileOutputStream(fileName)); } catch (Exception e) { e.printStackTrace(); } }
public static Configuration deserialize(String fileName) { try { JAXBContext jc = JAXBContext.newInstance((new Configuration()).getClass().getPackage().getName()); Unmarshaller um = jc.createUnmarshaller(); return (Configuration) um.unmarshal(new File(fileName)); } catch (Exception e) { e.printStackTrace(); return new Configuration(); } }
public void testXmlElementTypeDeser() throws Exception { ObjectMapper mapper = getJaxbMapper(); SimpleNamed originalModel = new SimpleNamed(); originalModel.setName("Foobar"); String json = mapper.writeValueAsString(originalModel); SimpleNamed result = null; try { result = mapper.readValue(json, SimpleNamed.class); } catch (Exception ie) { fail("Failed to deserialize '" + json + "': " + ie.getMessage()); } if (!"Foobar".equals(result.name)) { fail("Failed, JSON == '" + json + "')"); } }