use of gov.usgs.cida.coastalhazards.model.summary.Publication.PublicationType in project coastal-hazards by USGS-CIDA.
the class FullSummaryAdapter method deserialize.
@Override
public Full deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
Full result = new Full();
if (json instanceof JsonObject) {
JsonObject fullJson = (JsonObject) json;
result.setTitle(fullJson.getAsJsonPrimitive("title").getAsString());
result.setText(fullJson.getAsJsonPrimitive("text").getAsString());
List<Publication> fullPubList = new LinkedList<>();
JsonObject publications = fullJson.getAsJsonObject("publications");
for (PublicationType type : PublicationType.values()) {
JsonArray typedArray = publications.getAsJsonArray(type.name());
if (typedArray != null) {
List<Map<String, Object>> typeList = context.deserialize(typedArray, ArrayList.class);
for (Map<String, Object> pubMap : typeList) {
if (!pubMap.containsKey(Publication.TITLE) || !pubMap.containsKey(Publication.LINK)) {
throw new IllegalStateException("Expected publication, was not a publication");
}
Publication pub = new Publication();
pub.setTitle((String) pubMap.get(Publication.TITLE));
pub.setLink((String) pubMap.get(Publication.LINK));
pub.setType(type);
fullPubList.add(pub);
}
}
}
result.setPublications(fullPubList);
}
return result;
}
use of gov.usgs.cida.coastalhazards.model.summary.Publication.PublicationType in project coastal-hazards by USGS-CIDA.
the class FullSummaryAdapter method serialize.
@Override
public JsonElement serialize(Full src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject fullSummary = new JsonObject();
fullSummary.add("title", context.serialize(src.getTitle()));
fullSummary.add("text", context.serialize(src.getText()));
JsonObject publications = new JsonObject();
for (PublicationType type : PublicationType.values()) {
List<Publication> typedPubs = Publication.getTypedPublications(src.getPublications(), type);
publications.add(type.name(), context.serialize(typedPubs));
}
fullSummary.add("publications", publications);
return fullSummary;
}
Aggregations