use of org.n52.svalbard.decode.exception.DecodingException in project arctic-sea by 52North.
the class ContactJSONDecoder method decodeJSON.
@Override
public Contact decodeJSON(JsonNode node, boolean validate) throws DecodingException {
Contact contact = new Contact();
contact.setAddress(decodeJsonToNillable(node.path(AQDJSONConstants.ADDRESS), AddressRepresentation.class));
contact.setContactInstructions(parseNillable(node.path(AQDJSONConstants.CONTACT_INSTRUCTIONS)).map(this::parseFreeText));
contact.setElectronicMailAddress(parseNillableString(node.path(AQDJSONConstants.ELECTRONIC_MAIL_ADDRESS)));
contact.setHoursOfService(parseNillable(node.path(AQDJSONConstants.HOURS_OF_SERVICE)).map(this::parseFreeText));
contact.setWebsite(parseNillableString(node.path(AQDJSONConstants.WEBSITE)));
JsonNode tfNode = node.path(AQDJSONConstants.TELEPHONE_FACSIMILE);
if (tfNode.isArray()) {
for (JsonNode n : tfNode) {
contact.addTelephoneFacsimile(parseNillableString(n));
}
} else {
contact.addTelephoneFacsimile(parseNillableString(tfNode));
}
JsonNode tvNode = node.path(AQDJSONConstants.TELEPHONE_VOICE);
if (tvNode.isArray()) {
for (JsonNode n : tvNode) {
contact.addTelephoneVoice(parseNillableString(n));
}
} else {
contact.addTelephoneVoice(parseNillableString(tvNode));
}
return contact;
}
use of org.n52.svalbard.decode.exception.DecodingException in project arctic-sea by 52North.
the class EReportingHeaderJSONDecoder method decodeJSON.
@Override
public EReportingHeader decodeJSON(JsonNode node, boolean validate) throws DecodingException {
EReportingHeader header = new EReportingHeader();
header.setChange(decodeJsonToObject(node.path(AQDJSONConstants.CHANGE), EReportingChange.class));
header.setIdentifier(decodeJsonToObject(node.path(AQDJSONConstants.INSPIRE_ID), Identifier.class));
header.setReportingAuthority(decodeJsonToObject(node.path(AQDJSONConstants.REPORTING_AUTHORITY), RelatedParty.class));
header.setReportingPeriod(parseReferenceableTime(node.path(AQDJSONConstants.REPORTING_PERIOD)));
for (JsonNode child : node.path(AQDJSONConstants.CONTENT)) {
header.addContent(decodeJsonToReferencable(child, AbstractFeature.class));
}
for (JsonNode child : node.path(AQDJSONConstants.DELETE)) {
header.addDelete(decodeJsonToReferencable(child, AbstractFeature.class));
}
return header;
}
use of org.n52.svalbard.decode.exception.DecodingException in project arctic-sea by 52North.
the class FieldDecoder method decodeJSON.
public SweField decodeJSON(JsonNode node) throws DecodingException {
final String type = node.path(JSONConstants.TYPE).textValue();
final SweAbstractDataComponent element;
if (type.equals(JSONConstants.BOOLEAN_TYPE)) {
element = decodeBoolean(node);
} else if (type.equals(JSONConstants.COUNT_TYPE)) {
element = decodeCount(node);
} else if (type.equals(JSONConstants.COUNT_RANGE_TYPE)) {
element = decodeCountRange(node);
} else if (type.equals(JSONConstants.OBSERVABLE_PROPERTY_TYPE)) {
element = decodeObservableProperty(node);
} else if (type.equals(JSONConstants.QUALITY_TYPE)) {
element = decodeQuality(node);
} else if (type.equals(JSONConstants.TEXT_TYPE)) {
element = decodeText(node);
} else if (type.equals(JSONConstants.QUANTITY_TYPE)) {
element = decodeQuantity(node);
} else if (type.equals(JSONConstants.QUANTITY_RANGE_TYPE)) {
element = decodeQuantityRange(node);
} else if (type.equals(JSONConstants.TIME_TYPE)) {
element = decodeTime(node);
} else if (type.equals(JSONConstants.TIME_RANGE_TYPE)) {
element = decodeTimeRange(node);
} else if (type.equals(JSONConstants.CATEGORY_TYPE)) {
element = decodeCategory(node);
} else {
throw new UnsupportedDecoderInputException(this, node);
}
final String name = node.path(JSONConstants.NAME).textValue();
element.setDescription(node.path(JSONConstants.DESCRIPTION).textValue());
element.setIdentifier(node.path(JSONConstants.IDENTIFIER).textValue());
element.setDefinition(node.path(JSONConstants.DEFINITION).textValue());
element.setLabel(node.path(JSONConstants.LABEL).textValue());
return new SweField(name, element);
}
use of org.n52.svalbard.decode.exception.DecodingException in project arctic-sea by 52North.
the class FieldDecoder method decodeTimeRange.
protected SweAbstractDataComponent decodeTimeRange(JsonNode node) throws DecodingException {
SweTimeRange swe = new SweTimeRange();
if (node.hasNonNull(JSONConstants.VALUE)) {
String start = node.path(JSONConstants.VALUE).path(0).textValue();
String end = node.path(JSONConstants.VALUE).path(1).textValue();
swe.setValue(new RangeValue<DateTime>(parseDateTime(start), parseDateTime(end)));
}
return swe.setUom(node.path(JSONConstants.UOM).textValue());
}
use of org.n52.svalbard.decode.exception.DecodingException in project arctic-sea by 52North.
the class JSONValidator method validateAndThrow.
public void validateAndThrow(JsonNode instance, String schema) throws DecodingException {
ProcessingReport report = JSONValidator.getInstance().validate(instance, schema);
if (!report.isSuccess()) {
String message = encode(report, instance);
LOG.info("Invalid JSON instance:\n{}", message);
throw new JSONDecodingException(message);
}
}
Aggregations