use of com.fasterxml.jackson.core.JsonParser in project atlasmap by atlasmap.
the class JsonModule method getCollectionSize.
@Override
public int getCollectionSize(AtlasInternalSession session, Field field) throws AtlasException {
// TODO could this use FieldReader?
Object document = session.getSourceDocument(getDocId());
// make this a JSON document
JsonFactory jsonFactory = new JsonFactory();
ObjectMapper objectMapper = new ObjectMapper();
try {
JsonParser parser = jsonFactory.createParser(document.toString());
JsonNode rootNode = objectMapper.readTree(parser);
ObjectNode parentNode = (ObjectNode) rootNode;
String parentSegment = "[root node]";
for (SegmentContext sc : new AtlasPath(field.getPath()).getSegmentContexts(false)) {
JsonNode currentNode = JsonFieldWriter.getChildNode(parentNode, parentSegment, sc.getSegment());
if (currentNode == null) {
return 0;
}
if (AtlasPath.isCollectionSegment(sc.getSegment())) {
if (currentNode != null && currentNode.isArray()) {
return currentNode.size();
}
return 0;
}
parentNode = (ObjectNode) currentNode;
}
} catch (IOException e) {
throw new AtlasException(e.getMessage(), e);
}
return 0;
}
use of com.fasterxml.jackson.core.JsonParser in project atlasmap by atlasmap.
the class JsonFieldReader method setDocument.
public void setDocument(String document) throws AtlasException {
if (document == null || document.isEmpty()) {
throw new AtlasException(new IllegalArgumentException("document cannot be null nor empty"));
}
try {
JsonFactory factory = new JsonFactory();
ObjectMapper mapper = new ObjectMapper();
JsonParser parser = factory.createParser(document);
this.rootNode = mapper.readTree(parser);
} catch (Exception e) {
throw new AtlasException(e);
}
}
use of com.fasterxml.jackson.core.JsonParser in project uPortal by Jasig.
the class LayoutPortlet method isValidJSON.
private boolean isValidJSON(final String json) {
boolean valid = false;
try {
final JsonParser parser = new ObjectMapper().getFactory().createParser(json);
while (parser.nextToken() != null) {
}
valid = true;
} catch (Exception jpe) {
// eat error
valid = false;
}
return valid;
}
use of com.fasterxml.jackson.core.JsonParser in project Payara by payara.
the class ProgressStatusDTOJsonProprietaryReader method readFrom.
@Override
public ProgressStatusDTO readFrom(final InputStream is, final String contentType) throws IOException {
try (JsonParser jp = factory.createJsonParser(is)) {
// sorounding object
JsonToken token = jp.nextToken();
// Name progress-status
jp.nextToken();
JsonToken token2 = jp.nextToken();
if (token != JsonToken.START_OBJECT || token2 != JsonToken.START_OBJECT || !"progress-status".equals(jp.getCurrentName())) {
throw new IOException("Not expected type (progress-status) but (" + jp.getCurrentName() + ")");
}
return readProgressStatus(jp);
}
}
use of com.fasterxml.jackson.core.JsonParser in project Payara by payara.
the class ProgressStatusEventJsonProprietaryReader method readFrom.
@Override
public ProgressStatusEvent readFrom(final InputStream is, final String contentType) throws IOException {
try (JsonParser jp = factory.createJsonParser(is)) {
// sorounding object
JsonToken token = jp.nextToken();
// Name progress-status-event
jp.nextToken();
JsonToken token2 = jp.nextToken();
if (token != JsonToken.START_OBJECT || token2 != JsonToken.START_OBJECT || !"progress-status-event".equals(jp.getCurrentName())) {
throw new IOException("Not expected type (progress-status-event) but (" + jp.getCurrentName() + ")");
}
return readProgressStatusEvent(jp);
}
}
Aggregations