use of org.structr.core.rest.JsonInputGSONAdapter in project structr by structr.
the class ThreadLocalGson method initialValue.
@Override
protected Gson initialValue() {
final ResultGSONAdapter resultGsonAdapter = new ResultGSONAdapter(propertyView, outputNestingDepth);
final JsonInputGSONAdapter jsonInputAdapter = new JsonInputGSONAdapter();
// create GSON serializer
final GsonBuilder gsonBuilder = new GsonBuilder().setPrettyPrinting().serializeNulls().registerTypeHierarchyAdapter(FrameworkException.class, new FrameworkExceptionGSONAdapter()).registerTypeAdapter(IJsonInput.class, jsonInputAdapter).registerTypeAdapter(Result.class, resultGsonAdapter);
final boolean lenient = Settings.JsonLenient.getValue();
if (lenient) {
// Serializes NaN, -Infinity, Infinity, see http://code.google.com/p/google-gson/issues/detail?id=378
gsonBuilder.serializeSpecialFloatingPointValues();
}
return gsonBuilder.create();
}
use of org.structr.core.rest.JsonInputGSONAdapter in project structr by structr.
the class WebSocketDataGSONAdapter method deserialize.
@Override
public WebSocketMessage deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
WebSocketMessage webSocketData = new WebSocketMessage();
if (json instanceof JsonObject) {
JsonObject root = json.getAsJsonObject();
JsonObject nodeData = root.getAsJsonObject("data");
JsonObject relData = root.getAsJsonObject("relData");
if (root.has("command")) {
webSocketData.setCommand(root.getAsJsonPrimitive("command").getAsString());
}
if (root.has("id")) {
webSocketData.setId(root.getAsJsonPrimitive("id").getAsString());
}
if (root.has("pageId")) {
webSocketData.setPageId(root.getAsJsonPrimitive("pageId").getAsString());
}
if (root.has("sessionId")) {
JsonPrimitive sessionId = root.getAsJsonPrimitive("sessionId");
if (sessionId != null) {
webSocketData.setSessionId(sessionId.getAsString());
}
}
if (root.has("callback")) {
webSocketData.setCallback(root.getAsJsonPrimitive("callback").getAsString());
}
if (root.has("button")) {
webSocketData.setButton(root.getAsJsonPrimitive("button").getAsString());
}
if (root.has("parent")) {
webSocketData.setParent(root.getAsJsonPrimitive("parent").getAsString());
}
if (root.has("view")) {
webSocketData.setView(root.getAsJsonPrimitive("view").getAsString());
}
if (root.has("sort")) {
webSocketData.setSortKey(root.getAsJsonPrimitive("sort").getAsString());
}
if (root.has("order")) {
webSocketData.setSortOrder(root.getAsJsonPrimitive("order").getAsString());
}
if (root.has("pageSize")) {
webSocketData.setPageSize(root.getAsJsonPrimitive("pageSize").getAsInt());
}
if (root.has("page")) {
webSocketData.setPage(root.getAsJsonPrimitive("page").getAsInt());
}
if (nodeData != null) {
JsonInputGSONAdapter adapter = new JsonInputGSONAdapter();
for (Entry<String, JsonElement> entry : nodeData.entrySet()) {
final JsonElement obj = entry.getValue();
Object value = null;
if (obj instanceof JsonPrimitive) {
value = adapter.fromPrimitive(obj.getAsJsonPrimitive());
} else if (obj instanceof JsonObject) {
value = adapter.deserialize(obj, typeOfT, context);
} else if (obj instanceof JsonArray) {
final JsonArray array = obj.getAsJsonArray();
final List list = new LinkedList();
for (JsonElement element : array) {
if (element.isJsonPrimitive()) {
list.add(fromPrimitive((element.getAsJsonPrimitive())));
} else if (element.isJsonObject()) {
// create map of values
list.add(JsonInputGSONAdapter.deserialize(element, context));
}
}
value = list;
} else if (obj instanceof JsonNull) {
value = null;
} else if (obj != null) {
value = obj.getAsString();
}
webSocketData.setNodeData(entry.getKey(), value);
}
}
if (relData != null) {
for (Entry<String, JsonElement> entry : relData.entrySet()) {
JsonElement obj = entry.getValue();
if (obj instanceof JsonNull || obj.isJsonNull()) {
webSocketData.setRelData(entry.getKey(), null);
} else {
try {
webSocketData.setRelData(entry.getKey(), obj.getAsString());
} catch (Throwable t) {
webSocketData.setRelData(entry.getKey(), null);
}
}
}
}
}
return webSocketData;
}
Aggregations