List of usage examples for com.google.gson JsonObject JsonObject
JsonObject
From source file:arces.unibo.SEPA.commons.SPARQL.BindingsResults.java
License:Open Source License
public BindingsResults(BindingsResults newBindings) { results = new JsonObject(); JsonObject vars = new JsonObject(); JsonArray varArray = new JsonArray(); if (newBindings != null) for (String var : newBindings.getVariables()) { varArray.add(var); }/*from w ww. j av a2 s . co m*/ vars.add("vars", varArray); results.add("head", vars); JsonArray bindingsArray = new JsonArray(); if (newBindings != null) for (Bindings solution : newBindings.getBindings()) bindingsArray.add(solution.toJson()); JsonObject bindings = new JsonObject(); bindings.add("bindings", bindingsArray); results.add("results", bindings); }
From source file:arces.unibo.SEPA.commons.SPARQL.RDFTerm.java
License:Open Source License
public RDFTerm(String value) { json = new JsonObject(); json.add("value", new JsonPrimitive(value)); }
From source file:arces.unibo.SEPA.server.core.EngineProperties.java
License:Open Source License
protected void defaults() { JsonObject properties = new JsonObject(); // Engine timeouts JsonObject timeouts = new JsonObject(); timeouts.add("scheduling", new JsonPrimitive(0)); timeouts.add("queuesize", new JsonPrimitive(1000)); timeouts.add("keepalive", new JsonPrimitive(5000)); timeouts.add("http", new JsonPrimitive(5000)); properties.add("timeouts", timeouts); // Default path, scheme and port properties.add("path", new JsonPrimitive("/sparql")); properties.add("scheme", new JsonPrimitive("http")); properties.add("port", new JsonPrimitive(8000)); // Secure query JsonObject secureQuery = new JsonObject(); secureQuery.add("port", new JsonPrimitive(8443)); secureQuery.add("scheme", new JsonPrimitive("https")); properties.add("securequery", secureQuery); // Secure update JsonObject secureUpdate = new JsonObject(); secureUpdate.add("port", new JsonPrimitive(8443)); secureUpdate.add("scheme", new JsonPrimitive("https")); properties.add("secureupdate", secureUpdate); // Subscribe/*from w w w . jav a 2 s .c o m*/ JsonObject subscribe = new JsonObject(); subscribe.add("scheme", new JsonPrimitive("ws")); subscribe.add("port", new JsonPrimitive(9000)); properties.add("subscribe", subscribe); // Secure subscribe JsonObject secureSubscribe = new JsonObject(); secureSubscribe.add("scheme", new JsonPrimitive("wss")); secureSubscribe.add("port", new JsonPrimitive(9443)); secureSubscribe.add("path", new JsonPrimitive("/secure/sparql")); properties.add("securesubscribe", secureSubscribe); // Authorization server JsonObject authServer = new JsonObject(); authServer.add("port", new JsonPrimitive(8443)); authServer.add("scheme", new JsonPrimitive("https")); authServer.add("register", new JsonPrimitive("/oauth/register")); authServer.add("tokenrequest", new JsonPrimitive("/oauth/token")); properties.add("authorizationserver", authServer); parameters.add("parameters", properties); }
From source file:arces.unibo.SEPA.server.protocol.HTTPGate.java
License:Open Source License
/** * Builds the echo response./* w w w .j a va 2 s .c om*/ * * @param exchange * the exchange * @return the json object */ private JsonObject buildEchoResponse(HttpExchange exchange) { JsonObject json = new JsonObject(); json.add("method", new JsonPrimitive(exchange.getRequestMethod().toUpperCase())); json.add("protocol", new JsonPrimitive(exchange.getProtocol())); JsonObject headers = new JsonObject(); for (String header : exchange.getRequestHeaders().keySet()) { headers.add(header, new JsonPrimitive(exchange.getRequestHeaders().get(header).toString())); } json.add("headers", headers); String body = ""; try { body = IOUtils.toString(exchange.getRequestBody(), "UTF-8"); } catch (IOException e) { logger.error(e.getMessage()); body = e.getMessage(); } json.add("body", new JsonPrimitive(body)); json.add("contextPath", new JsonPrimitive(exchange.getHttpContext().getPath())); if (exchange.getRequestURI().getQuery() != null) json.add("query", new JsonPrimitive(exchange.getRequestURI().getQuery())); return json; }
From source file:assignment3.Assignment3.java
public static String getJSON() { String output = ""; try {// w w w. j a va 2 s .c o m JsonArray arr = new JsonArray(); Connection conn = getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM students"); while (rs.next()) { JsonObject obj = new JsonObject(); obj.addProperty("id", rs.getInt("id")); obj.addProperty("fName", rs.getString("fName")); obj.addProperty("lName", rs.getString("lName")); obj.addProperty("bio", rs.getString("bio")); arr.add(obj); } output = arr.toString(); conn.close(); } catch (SQLException ex) { output = "SQL Exception Error: " + ex.getMessage(); } return output; }
From source file:assignment3.Assignment3.java
public static String getJSON(int id) { String output = ""; try {//from w w w. j a va 2s .c o m JsonArray arr = new JsonArray(); Connection conn = getConnection(); String query = "SELECT * FROM students WHERE id = ?"; PreparedStatement pstmt = conn.prepareStatement(query); pstmt.setInt(1, id); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { JsonObject obj = new JsonObject(); obj.addProperty("id", rs.getInt("id")); obj.addProperty("fName", rs.getString("fName")); obj.addProperty("lName", rs.getString("lName")); obj.addProperty("bio", rs.getString("bio")); arr.add(obj); } output = arr.toString(); conn.close(); } catch (SQLException ex) { output = "SQL Exception Error: " + ex.getMessage(); } return output; }
From source file:at.ac.tuwien.infosys.jcloudscale.datastore.mapping.json.JsonMapperImpl.java
License:Apache License
@Override public String serialize(Object object) { JsonObject jsonObject = new JsonObject(); ObjectNavigator objectNavigator = new ObjectNavigatorImpl(typeAdapterFactory); Visitor visitor = new JsonSerializationVisitor(jsonObject); objectNavigator.navigate(object, visitor); return gson.toJson(jsonObject); }
From source file:at.ac.tuwien.infosys.jcloudscale.datastore.mapping.json.JsonSerializationVisitor.java
License:Apache License
private JsonElement handleUserDefined(Object value, TypeMetadata<JsonElement> typeMetadata) { if (typeMetadata.isCustomTypeAdapterPresent()) { TypeAdapter typeAdapter = typeMetadata.getTypeAdapter(); return (JsonElement) typeAdapter.serialize(value, typeMetadata); } else {/*w w w . j a v a2 s.com*/ JsonObject jsonObject = new JsonObject(); ObjectNavigator objectNavigator = new ObjectNavigatorImpl(new JsonTypeAdapterFactory()); Visitor visitor = new JsonSerializationVisitor(jsonObject); objectNavigator.navigate(value, visitor); return jsonObject; } }
From source file:at.ac.tuwien.infosys.jcloudscale.datastore.mapping.type.json.JsonMapTypeAdapter.java
License:Apache License
@Override public JsonElement serialize(Map<?, ?> object, TypeMetadata<JsonElement> typeMetadata) { JsonObject jsonObject = new JsonObject(); TypeAdapter valueTypeAdapter = typeMetadata.getTypeParameterTypeAdapters().get(1); for (Object key : object.keySet()) { JsonElement valueElement = (JsonElement) valueTypeAdapter.serialize(object.get(key), typeMetadata); jsonObject.add(String.valueOf(key), valueElement); }/*from www. java 2 s . c o m*/ return jsonObject; }
From source file:at.ac.tuwien.infosys.jcloudscale.datastore.mapping.type.json.JsonTypeParameterTypeAdapter.java
License:Apache License
@Override public JsonElement serialize(Object object, TypeMetadata<JsonElement> typeMetadata) { JsonObject jsonObject = new JsonObject(); ObjectNavigator objectNavigator = new ObjectNavigatorImpl(typeAdapterFactory); Visitor visitor = new JsonSerializationVisitor(jsonObject); objectNavigator.navigate(object, visitor); return jsonObject; }