HarvestHistory extends GeonetEntity { @Override protected Element asXml(IdentityHashMap<Object, Void> alreadyEncoded) { final Element element = super.asXml(alreadyEncoded); Element infoAsXml = null; try { infoAsXml = getInfoAsXml(); } catch (IOException e) { Log.warning(Constants.DOMAIN_LOG_MODULE, "error parsing harvest history info element", e); } catch (JDOMException e) { Log.warning(Constants.DOMAIN_LOG_MODULE, "error parsing harvest history info element", e); } Element paramsAsXml = null; try { paramsAsXml = getParamsAsXml(); } catch (IOException e) { Log.warning(Constants.DOMAIN_LOG_MODULE, "error parsing harvest history params element", e); } catch (JDOMException e) { Log.warning(Constants.DOMAIN_LOG_MODULE, "error parsing harvest history params element", e); } replaceWithXml(element, infoAsXml, "info"); replaceWithXml(element, paramsAsXml, "params"); return element; }  @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = ID_SEQ_NAME) int getId(); HarvestHistory setId(int id); @AttributeOverride(name = "dateAndTime", column = @Column(name = "harvestdate", length = 30)) ISODate getHarvestDate(); HarvestHistory setHarvestDate(ISODate harvestDate); @Column(name = "elapsedtime") int getElapsedTime(); HarvestHistory setElapsedTime(int elapsedTime); @Column(name = "harvesteruuid") String getHarvesterUuid(); HarvestHistory setHarvesterUuid(String harvesterUuid); @Column(name = "harvestername") String getHarvesterName(); HarvestHistory setHarvesterName(String harvesterName); @Column(name = "harvestertype") String getHarvesterType(); HarvestHistory setHarvesterType(String harvesterType); @Transient boolean isDeleted(); HarvestHistory setDeleted(boolean deleted); @Lob @Type(type = "org.hibernate.type.StringClobType") // this is a work around for postgres so postgres can correctly load clobs String getInfo(); @Nonnull HarvestHistory setInfo(@Nullable Element info); @Transient @Nullable Element getInfoAsXml(); @Lob @Type(type = "org.hibernate.type.StringClobType") // this is a work around for postgres so postgres can correctly load clobs String getParams(); HarvestHistory setParams(final Element params); @Transient @Nullable Element getParamsAsXml();  }
@Test public void testAsXml() throws Exception { final HarvestHistory harvestHistory = HarvestHistoryRepositoryTest.createHarvestHistory(_inc); harvestHistory.setHarvestDate(new ISODate()); harvestHistory.setInfo(new Element("rootInfo").addContent(new Element("child").setText("text"))); harvestHistory.setParams(new Element("rootParam").addContent(new Element("child").setText("text"))); final Element xml = harvestHistory.asXml(); assertEquals(harvestHistory.getHarvestDate(), new ISODate(xml.getChildText("harvestdate"))); final Element info = xml.getChild("info"); assertTrue(info.getChildren().get(0) instanceof Element); final Element params = xml.getChild("params"); assertTrue(params.getChildren().get(0) instanceof Element); }