List of usage examples for com.fasterxml.jackson.databind.node NullNode getInstance
public static NullNode getInstance()
From source file:com.baasbox.commands.UsersResource.java
protected JsonNode changePassword(JsonNode command, JsonCallback unused) throws CommandException { String username = getUsername(command); JsonNode newPasswordJson = getParamField(command, "newPassword"); if (newPasswordJson == null || !newPasswordJson.isTextual()) throw new CommandExecutionException(command, "invalid new password: " + newPasswordJson); String newPassword = newPasswordJson.asText(); try {// w w w .j ava 2s . co m UserService.changePassword(username, newPassword); } catch (UserNotFoundException | OpenTransactionException | SqlInjectionException e) { throw new CommandExecutionException(command, ExceptionUtils.getMessage(e), e); } return NullNode.getInstance(); }
From source file:com.almende.eve.state.ConcurrentJsonFileState.java
@Override public synchronized JsonNode locPut(final String key, JsonNode value) { JsonNode result = null;/*from w ww .jav a 2 s . c o m*/ try { openFile(); read(); if (value == null) { value = NullNode.getInstance(); } result = properties.put(key, value); write(); } catch (final Exception e) { LOG.log(Level.WARNING, "", e); } closeFile(); return result; }
From source file:com.almende.eve.state.file.ConcurrentJsonFileState.java
@Override @JsonIgnore//from w w w .j av a 2 s. co m public JsonNode get(final String key) { JsonNode result = NullNode.getInstance(); try { openFile(); read(); result = properties.get(key); } catch (final IllegalStateException e) { LOG.log(Level.WARNING, "Couldn't handle Statefile: " + e.getMessage(), e); } catch (final Exception e) { LOG.log(Level.WARNING, "", e); } closeFile(); return result; }
From source file:org.modeshape.web.jcr.rest.handler.ItemHandlerImpl.java
private Object convertToJcrValues(Node node, Object value, boolean encoded) throws RepositoryException { if (value == NullNode.getInstance() || (value instanceof ArrayNode && ((ArrayNode) value).size() == 0)) { // for any null value of empty json array, return an empty array which will mean the property will be removed return null; }//from w ww . ja v a 2 s . c o m org.modeshape.jcr.api.ValueFactory valueFactory = (org.modeshape.jcr.api.ValueFactory) node.getSession() .getValueFactory(); if (value instanceof ArrayNode) { ArrayNode jsonValues = (ArrayNode) value; Value[] values = new Value[jsonValues.size()]; for (int i = 0; i < jsonValues.size(); i++) { if (encoded) { values[i] = createBinaryValue(jsonValues.get(i).asText(), valueFactory); } else { values[i] = RestHelper.jsonValueToJCRValue(jsonValues.get(i), valueFactory); } } return values; } return encoded ? createBinaryValue(value.toString(), valueFactory) : RestHelper.jsonValueToJCRValue(value, valueFactory); }
From source file:com.almende.eve.state.ConcurrentJsonFileState.java
@Override public synchronized boolean locPutIfUnchanged(final String key, final JsonNode newVal, JsonNode oldVal) { boolean result = false; try {/*from w w w . j a va2 s .c om*/ openFile(); read(); JsonNode cur = NullNode.getInstance(); if (properties.containsKey(key)) { cur = properties.get(key); } if (oldVal == null) { oldVal = NullNode.getInstance(); } // Poor mans equality as some Numbers are compared incorrectly: e.g. // IntNode versus LongNode if (oldVal.equals(cur) || oldVal.toString().equals(cur.toString())) { properties.put(key, newVal); write(); result = true; } } catch (final Exception e) { LOG.log(Level.WARNING, "", e); // Don't let users loop if exception is thrown. They // would get into a deadlock.... result = true; } closeFile(); return result; }
From source file:com.almende.eve.state.file.ConcurrentJsonFileState.java
@Override public JsonNode locPut(final String key, JsonNode value) { try {// w w w .j a va 2 s . c o m openFile(); read(); if (value == null) { value = NullNode.getInstance(); } properties.put(key, value); write(); } catch (final IllegalStateException e) { LOG.log(Level.WARNING, "Couldn't handle Statefile: " + e.getMessage(), e); } catch (final Exception e) { LOG.log(Level.WARNING, "", e); } closeFile(); return value; }
From source file:org.apache.usergrid.java.client.model.UsergridEntity.java
public void putProperty(@NotNull final String name, @Nullable final JsonNode value) { UsergridEntityProperties entityProperty = UsergridEntityProperties.fromString(name); if (entityProperty != null && !entityProperty.isMutableForEntity(this)) { return;//from w w w.j a v a 2 s . c o m } JsonNode valueNode = value; if (valueNode == null) { valueNode = NullNode.getInstance(); } this.updatePropertiesWithMap(Collections.singletonMap(name, valueNode)); }
From source file:com.almende.eve.state.file.ConcurrentJsonFileState.java
@Override public boolean locPutIfUnchanged(final String key, final JsonNode newVal, JsonNode oldVal) { boolean result = false; try {// w w w . j a v a2 s . c om openFile(); read(); JsonNode cur = NullNode.getInstance(); if (properties.containsKey(key)) { cur = properties.get(key); } if (oldVal == null) { oldVal = NullNode.getInstance(); } // Poor mans equality as some Numbers are compared incorrectly: e.g. // IntNode versus LongNode if (oldVal.equals(cur) || oldVal.toString().equals(cur.toString())) { properties.put(key, newVal); write(); result = true; } } catch (final IllegalStateException e) { LOG.log(Level.WARNING, "Couldn't handle Statefile: " + e.getMessage(), e); } catch (final Exception e) { LOG.log(Level.WARNING, "", e); // Don't let users loop if exception is thrown. They // would get into a deadlock.... result = true; } closeFile(); return result; }
From source file:com.unboundid.scim2.common.utils.JsonUtils.java
/** * Gets a single value (node) from an ObjectNode at the supplied path. * It is expected that there will only be one matching path. If there * are multiple matching paths (for example a path with filters can * match multiple nodes), an exception will be thrown. * * For example:// ww w . j a v a 2 s . c om * With an ObjectNode representing: * { * "name":"Bob", * "favoriteColors":["red","green","blue"] * } * * getValue(Path.fromString("name") * will return a TextNode containing "{@code Bob}" * * getValue(Path.fromString("favoriteColors")) * will return an ArrayNode containing TextNodes with the following * values - "{@code red}", "{@code green}", and "{@code blue}". * * @param path The path to the attributes whose values to retrieve. * @param node the ObjectNode to find the path in. * @return the node located at the path, or a NullNode. * @throws ScimException throw in case of errors. */ public static JsonNode getValue(final Path path, final ObjectNode node) throws ScimException { GatheringNodeVisitor visitor = new GatheringNodeVisitor(false); traverseValues(visitor, node, 0, path); if (visitor.values.isEmpty()) { return NullNode.getInstance(); } else { return visitor.values.get(0); } }
From source file:com.baasbox.commands.UsersResource.java
@Override protected JsonNode post(JsonNode command) throws CommandException { try {//w w w . j a v a 2 s.co m JsonNode params = command.get(ScriptCommand.PARAMS); if (params == null || !params.isObject()) throw new CommandParsingException(command, "missing parameters"); String username = getUsername(command); JsonNode password = params.get("password"); if (password == null || !password.isTextual()) throw new CommandParsingException(command, "missing required password"); JsonNode id = params.get(BaasBoxPrivateFields.ID.toString()); String idString = null; if (!(id instanceof NullNode) && id != null && !id.isTextual()) throw new CommandParsingException(command, "ID must be a string"); if (!(id instanceof NullNode) && id != null && id.isTextual() && StringUtils.isBlank(id.asText())) throw new CommandParsingException(command, "ID cannot be empty or cannot contains only whitespaces"); if (!(id instanceof NullNode) && id != null && id.isTextual()) idString = id.asText(); JsonNode roleNode = params.get("role"); String role; if (roleNode == null) { role = DefaultRoles.REGISTERED_USER.getORole().getName(); } else if (roleNode.isTextual()) { role = roleNode.asText(); } else { throw new CommandParsingException(command, "role parameter is not valid"); } if (!RoleService.exists(role)) { throw new CommandExecutionException(command, "required role does not exists: " + role); } JsonNode userVisible = params.get(UserDao.ATTRIBUTES_VISIBLE_ONLY_BY_THE_USER); JsonNode friendsVisible = params.get(UserDao.ATTRIBUTES_VISIBLE_BY_FRIENDS_USER); JsonNode registeredVisible = params.get(UserDao.ATTRIBUTES_VISIBLE_BY_REGISTERED_USER); JsonNode anonymousVisible = params.get(UserDao.ATTRIBUTES_VISIBLE_BY_ANONYMOUS_USER); ODocument user = UserService.signUp(username, password.asText(), new Date(), role, anonymousVisible, userVisible, friendsVisible, registeredVisible, false, idString); String userNode = JSONFormats.prepareDocToJson(user, JSONFormats.Formats.USER); return Json.mapper().readTree(userNode); } catch (InvalidJsonException | IOException e) { throw new CommandExecutionException(command, "invalid json", e); } catch (UserAlreadyExistsException | EmailAlreadyUsedException e) { return NullNode.getInstance(); } }