use of javax.json.JsonValue in project sling by apache.
the class JsonContentParser method parse.
private void parse(ContentHandler handler, JsonObject object, String path) {
// parse JSON object
Map<String, Object> properties = new HashMap<>();
Map<String, JsonObject> children = new LinkedHashMap<>();
for (Map.Entry<String, JsonValue> entry : object.entrySet()) {
String childName = entry.getKey();
Object value = convertValue(entry.getValue());
boolean isResource = (value instanceof JsonObject);
boolean ignore = false;
if (isResource) {
ignore = helper.ignoreResource(childName);
} else {
childName = helper.cleanupPropertyName(childName);
ignore = helper.ignoreProperty(childName);
}
if (!ignore) {
if (isResource) {
children.put(childName, (JsonObject) value);
} else {
properties.put(childName, value);
}
}
}
helper.ensureDefaultPrimaryType(properties);
// report current JSON object
handler.resource(path, properties);
// parse and report children
for (Map.Entry<String, JsonObject> entry : children.entrySet()) {
String childPath = helper.concatenatePath(path, entry.getKey());
;
parse(handler, entry.getValue(), childPath);
}
}
use of javax.json.JsonValue in project sling by apache.
the class JsonReader method createPrincipal.
/**
* Create or update a user or group
*/
private void createPrincipal(JsonObject json, ContentCreator contentCreator) throws RepositoryException {
//create a principal
String name = json.getString("name");
boolean isGroup = json.getBoolean("isgroup", false);
//collect the extra property names to assign to the new principal
Map<String, Object> extraProps = new LinkedHashMap<String, Object>();
for (Map.Entry<String, JsonValue> entry : json.entrySet()) {
String propName = entry.getKey();
if (!ignoredPrincipalPropertyNames.contains(propName)) {
Object value = unbox(entry.getValue());
extraProps.put(propName, value);
}
}
if (isGroup) {
String[] members = null;
JsonArray membersJSONArray = (JsonArray) json.get("members");
if (membersJSONArray != null) {
members = new String[membersJSONArray.size()];
for (int i = 0; i < members.length; i++) {
members[i] = membersJSONArray.getString(i);
}
}
contentCreator.createGroup(name, members, extraProps);
} else {
String password = json.getString("password");
contentCreator.createUser(name, password, extraProps);
}
}
use of javax.json.JsonValue in project sling by apache.
the class JsonRenderer method skipChildObject.
/** Decide whether o must be skipped and added to a, when rendering a JSONObject */
private boolean skipChildObject(JsonArrayBuilder a, Options opt, String key, Object value) {
if (opt.arraysForChildren && (value instanceof JsonObject)) {
JsonObjectBuilder builder = Json.createObjectBuilder();
builder.add(opt.childNameKey, key);
for (Map.Entry<String, JsonValue> entry : ((JsonObject) value).entrySet()) {
builder.add(entry.getKey(), entry.getValue());
}
a.add(builder);
return true;
}
return false;
}
use of javax.json.JsonValue in project sling by apache.
the class JsonRenderer method valueToString.
/**
* Make a JSON text of an Object value.
* <p>
* Warning: This method assumes that the data structure is acyclical.
* @param value The value to be serialized.
* @return a printable, displayable, transmittable
* representation of the object, beginning
* with <code>{</code> <small>(left brace)</small> and ending
* with <code>}</code> <small>(right brace)</small>.
* @throws JSONException If the value is or contains an invalid number.
*/
public String valueToString(Object value) {
// TODO call the other valueToString instead
if (value == null || value.equals(null)) {
return "null";
}
if (value instanceof JsonString) {
quote(((JsonString) value).getString());
}
if (value instanceof Number) {
return numberToString((Number) value);
}
if (value instanceof Boolean) {
return value.toString();
}
if (value instanceof JsonObject || value instanceof JsonArray) {
StringWriter writer = new StringWriter();
Json.createGenerator(writer).write((JsonValue) value).close();
return writer.toString();
}
return quote(value.toString());
}
use of javax.json.JsonValue in project traccar by tananaev.
the class FlespiProtocolDecoder method decodePosition.
private void decodePosition(JsonObject object, Position position) {
for (Map.Entry<String, JsonValue> param : object.entrySet()) {
String paramName = param.getKey();
JsonValue paramValue = param.getValue();
int index = -1;
if (paramName.contains("#")) {
String[] parts = paramName.split("#");
paramName = parts[0];
index = Integer.parseInt(parts[1]);
}
if (!decodeParam(paramName, index, paramValue, position)) {
decodeUnknownParam(param.getKey(), param.getValue(), position);
}
}
if (position.getLatitude() == 0 && position.getLongitude() == 0) {
getLastLocation(position, position.getDeviceTime());
}
}
Aggregations