use of com.fasterxml.jackson.databind.node.ArrayNode in project asterixdb by apache.
the class NodesAPIIntegrationTest method getNodeIds.
private List<String> getNodeIds() throws IOException, URISyntaxException {
ArrayNode nodes = getNodeSummaries();
final int size = nodes.size();
List<String> nodeIds = new ArrayList<>();
for (int i = 0; i < size; ++i) {
nodeIds.add(nodes.get(i).get("node-id").asText());
}
return nodeIds;
}
use of com.fasterxml.jackson.databind.node.ArrayNode in project asterixdb by apache.
the class ABinary method toJSON.
@Override
public ObjectNode toJSON() {
ObjectMapper om = new ObjectMapper();
ObjectNode json = om.createObjectNode();
int start = getStart();
ArrayNode byteArray = om.createArrayNode();
for (int i = 0; i < getLength(); i++) {
byteArray.add(bytes[start + i]);
}
json.set("ABinary", byteArray);
return json;
}
use of com.fasterxml.jackson.databind.node.ArrayNode in project JMRI by JMRI.
the class JsonNamedBeanHttpService method getNamedBean.
/**
* Create the JsonNode for a {@link jmri.NamedBean} object.
*
* @param bean the bean to create the node for
* @param name the name of the bean; used only if the bean is null
* @param type the JSON type of the bean
* @param locale the locale used for any error messages
* @return a JSON node
* @throws JsonException if the bean is null
*/
@Nonnull
protected ObjectNode getNamedBean(NamedBean bean, @Nonnull String name, @Nonnull String type, @Nonnull Locale locale) throws JsonException {
if (bean == null) {
throw new JsonException(404, Bundle.getMessage(locale, "ErrorObject", type, name));
}
ObjectNode root = mapper.createObjectNode();
root.put(JSON.TYPE, type);
ObjectNode data = root.putObject(JSON.DATA);
data.put(JSON.NAME, bean.getSystemName());
data.put(JSON.USERNAME, bean.getUserName());
data.put(JSON.COMMENT, bean.getComment());
ArrayNode properties = root.putArray(JSON.PROPERTIES);
bean.getPropertyKeys().stream().forEach((key) -> {
Object value = bean.getProperty(key);
if (value != null) {
properties.add(mapper.createObjectNode().put(key, value.toString()));
} else {
properties.add(mapper.createObjectNode().putNull(key));
}
});
return data;
}
use of com.fasterxml.jackson.databind.node.ArrayNode in project JMRI by JMRI.
the class JsonConsistHttpService method getConsist.
/**
* Get the JSON representation of a consist.
*
* The JSON representation is an object with the following data attributes:
* <ul>
* <li>address - integer address</li>
* <li>isLongAddress - boolean true if address is long, false if short</li>
* <li>type - integer, see {@link jmri.Consist#getConsistType() }</li>
* <li>id - string with consist Id</li>
* <li>sizeLimit - the maximum number of locomotives the consist can
* contain</li>
* <li>engines - array listing every locomotive in the consist. Each entry
* in the array contains the following attributes:
* <ul>
* <li>address - integer address</li>
* <li>isLongAddress - boolean true if address is long, false if short</li>
* <li>forward - boolean true if the locomotive running is forward in the
* consists</li>
* <li>position - integer locomotive's position in the consist</li>
* </ul>
* </ul>
*
* @param locale The locale to throw exceptions in.
* @param address The address of the consist to get.
* @return The JSON representation of the consist.
* @throws JsonException This exception has code 404 if the consist does not
* exist.
*/
public JsonNode getConsist(Locale locale, DccLocoAddress address) throws JsonException {
if (this.manager.getConsistList().contains(address)) {
ObjectNode root = mapper.createObjectNode();
root.put(TYPE, CONSIST);
ObjectNode data = root.putObject(DATA);
Consist consist = this.manager.getConsist(address);
data.put(ADDRESS, consist.getConsistAddress().getNumber());
data.put(IS_LONG_ADDRESS, consist.getConsistAddress().isLongAddress());
data.put(TYPE, consist.getConsistType());
ArrayNode engines = data.putArray(ENGINES);
consist.getConsistList().stream().forEach((locomotive) -> {
ObjectNode engine = mapper.createObjectNode();
engine.put(ADDRESS, locomotive.getNumber());
engine.put(IS_LONG_ADDRESS, locomotive.isLongAddress());
engine.put(FORWARD, consist.getLocoDirection(locomotive));
engine.put(POSITION, consist.getPosition(locomotive));
engines.add(engine);
});
data.put(ID, consist.getConsistID());
data.put(SIZE_LIMIT, consist.sizeLimit());
return root;
} else {
// NOI18N
throw new JsonException(404, Bundle.getMessage(locale, "ErrorObject", CONSIST, address.toString()));
}
}
use of com.fasterxml.jackson.databind.node.ArrayNode in project JMRI by JMRI.
the class JsonOperationsHttpService method getCars.
public ArrayNode getCars(Locale locale) {
ArrayNode root = mapper.createArrayNode();
CarManager.instance().getByIdList().forEach((rs) -> {
root.add(this.utilities.getCar(locale, rs.getId()));
});
return root;
}
Aggregations