use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project crnk-framework by crnk-project.
the class ClientResourceUpsert method setLinks.
protected void setLinks(Resource dataBody, Object instance, ResourceInformation resourceInformation) {
ResourceField linksField = resourceInformation.getLinksField();
if (dataBody.getLinks() != null && linksField != null) {
JsonNode linksNode = dataBody.getLinks();
Class<?> linksClass = linksField.getType();
ObjectReader linksMapper = objectMapper.readerFor(linksClass);
try {
Object links = linksMapper.readValue(linksNode);
linksField.getAccessor().setValue(instance, links);
} catch (IOException e) {
throw new ResponseBodyException("failed to parse links information", e);
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project ma-core-public by infiniteautomation.
the class DataPointEventsByDataPointRQLQueryDefinition method validateImpl.
/* (non-Javadoc)
* @see com.serotonin.m2m2.module.ModuleQueryDefinition#validateImpl(com.fasterxml.jackson.databind.JsonNode)
*/
@Override
protected void validateImpl(final User user, final JsonNode parameters, final RestValidationResult result) {
if (parameters.get("rql") == null)
result.addRequiredError("rql");
else {
try {
JsonNode rqlNode = parameters.get("rql");
ObjectReader reader = Common.objectMapper.getObjectReader(String.class);
String rql = reader.readValue(rqlNode);
if (rql != null && !rql.isEmpty()) {
RQLParser parser = new RQLParser();
parser.parse(rql);
}
} catch (IOException | RQLParserException | IllegalArgumentException e) {
result.addInvalidValueError("rql");
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project ma-core-public by infiniteautomation.
the class DataPointEventsByTagQueryDefinition method createQuery.
/* (non-Javadoc)
* @see com.serotonin.m2m2.module.ModuleQueryDefinition#createQuery(com.fasterxml.jackson.databind.JsonNode)
*/
@Override
public ASTNode createQuery(User user, JsonNode parameters) throws IOException {
JsonNode tagsNode = parameters.get("tags");
ObjectReader reader = Common.objectMapper.getObjectReader(Map.class);
Map<String, String> tags = reader.readValue(tagsNode);
// Lookup data points by tag
List<Object> args = new ArrayList<>();
args.add("typeRef1");
DataPointDao.instance.dataPointsForTags(tags, user, new MappedRowCallback<DataPointVO>() {
@Override
public void row(DataPointVO dp, int index) {
if (Permissions.hasDataPointReadPermission(user, dp)) {
args.add(Integer.toString(dp.getId()));
}
}
});
// Create Event Query for these Points
if (args.size() > 0) {
ASTNode query = new ASTNode("in", args);
query = addAndRestriction(query, new ASTNode("eq", "userId", user.getId()));
query = addAndRestriction(query, new ASTNode("eq", "typeName", "DATA_POINT"));
// TODO Should we force a limit if none is supplied?
if (parameters.has("limit")) {
int offset = 0;
int limit = parameters.get("limit").asInt();
if (parameters.has("offset"))
offset = parameters.get("offset").asInt();
query = addAndRestriction(query, new ASTNode("limit", limit, offset));
}
return query;
} else {
return new ASTNode("limit", 0, 0);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project syndesis by syndesisio.
the class ExtensionSerializationTest method testSerializeDeserialize.
@Test
public void testSerializeDeserialize() throws IOException {
final ObjectReader reader = Json.reader();
final ObjectWriter writer = Json.writer();
try (InputStream source = getClass().getResourceAsStream("syndesis-extension-definition.json")) {
try {
reader.forType(Extension.class).readValue(writer.writeValueAsString(new Extension.Builder().createFrom(reader.forType(Extension.class).readValue(source)).build()));
} catch (IOException e) {
fail("Should not throw an exception");
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader in project syndesis by syndesisio.
the class JsonDbDao method fetchAll.
@Override
@SuppressWarnings({ "unchecked", "PMD.CyclomaticComplexity" })
public ListResult<T> fetchAll(Function<ListResult<T>, ListResult<T>>... operators) {
try {
GetOptions options = new GetOptions();
// Try to convert operators to equivalent DB queries.
if (operators != null) {
for (int i = 0; i < operators.length; i++) {
Function<ListResult<T>, ListResult<T>> operator = operators[i];
if (operator.getClass() == IdPrefixFilter.class) {
IdPrefixFilter<T> filter = (IdPrefixFilter<T>) operator;
options.startAt(":" + filter.getPrefix());
options.endAt(":" + filter.getPrefix());
// Take it out of the list.
operators[i] = null;
}
}
}
// get the data out..
byte[] json = jsondb.getAsByteArray(getCollectionPath(), options);
ListResult<T> result;
if (json != null && json.length > 0) {
// Lets use jackson to parse the map of keys to our model instances
ObjectReader reader = Json.reader();
TypeFactory typeFactory = reader.getTypeFactory();
MapType mapType = typeFactory.constructMapType(LinkedHashMap.class, String.class, getType());
LinkedHashMap<String, T> map = reader.forType(mapType).readValue(json);
result = ListResult.of(map.values());
} else {
result = ListResult.of(Collections.<T>emptyList());
}
if (operators == null) {
return result;
}
for (Function<ListResult<T>, ListResult<T>> operator : operators) {
if (operator != null) {
result = operator.apply(result);
}
}
return result;
} catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") RuntimeException | IOException e) {
throw SyndesisServerException.launderThrowable(e);
}
}
Aggregations