Example usage for com.google.gson JsonPrimitive JsonPrimitive

List of usage examples for com.google.gson JsonPrimitive JsonPrimitive

Introduction

In this page you can find the example usage for com.google.gson JsonPrimitive JsonPrimitive.

Prototype

public JsonPrimitive(Character c) 

Source Link

Document

Create a primitive containing a character.

Usage

From source file:com.adnanbal.fxdedektifi.forex.data.net.ApiConnection.java

License:Apache License

/**
 * Do a request to an api synchronously.
 * It should not be executed in the main thread of the application.
 *
 * @return A string response//from  www .  j a  v a  2 s .  c  om
 */
@Nullable
String request_postSyncCall(NewPositionEntity newPositionEntity) {
    final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(Date.class,
                    (JsonDeserializer<Date>) (jsonElement, type,
                            context) -> new Date(jsonElement.getAsJsonPrimitive().getAsLong()))
            .registerTypeAdapter(Date.class,
                    (JsonSerializer<Date>) (date, type,
                            jsonSerializationContext) -> new JsonPrimitive(date.getTime()))

            .create();
    String jsonInString = gson.toJson(newPositionEntity);

    RequestBody body = RequestBody.create(JSON, jsonInString);

    postRequestToApi(body);
    i++;
    return response;
}

From source file:com.adnanbal.fxdedektifi.forex.data.net.ApiConnection.java

License:Apache License

@Nullable
String request_postNewSignalSyncCall(NewPositionEntity newPositionEntity) {
    final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(Date.class,
                    (JsonDeserializer<Date>) (jsonElement, type,
                            context) -> new Date(jsonElement.getAsJsonPrimitive().getAsLong()))
            .registerTypeAdapter(Date.class,
                    (JsonSerializer<Date>) (date, type,
                            jsonSerializationContext) -> new JsonPrimitive(date.getTime()))

            .create();/*from   www.j  av  a2 s  .  c  o  m*/
    String jsonInString = gson.toJson(newPositionEntity);

    RequestBody body = RequestBody.create(JSON, jsonInString);

    postRequestToApiNewSignal(body);
    i++;
    return response;
}

From source file:com.adnanbal.fxdedektifi.forex.data.net.ApiConnection.java

License:Apache License

/**
 * Do a request to an api synchronously.
 * It should not be executed in the main thread of the application.
 *
 * @return A string response//from   w w w . ja  v  a 2 s . co m
 */
@Nullable
String request_postUserLoginDetailEntitySyncCall(UserLoginDetailsEntity userLoginDetailsEntity) {
    final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(Date.class,
                    (JsonDeserializer<Date>) (jsonElement, type,
                            context) -> new Date(jsonElement.getAsJsonPrimitive().getAsLong()))
            .registerTypeAdapter(Date.class,
                    (JsonSerializer<Date>) (date, type,
                            jsonSerializationContext) -> new JsonPrimitive(date.getTime()))

            .create();
    String jsonInString = gson.toJson(userLoginDetailsEntity);

    RequestBody body = RequestBody.create(JSON, jsonInString);

    postRequestToApi(body);
    i++;
    return response;
}

From source file:com.adnanbal.fxdedektifi.forex.data.net.ApiConnection.java

License:Apache License

@Nullable
String request_putSyncCall(PositionEntity positionEntity) {
    final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(Date.class,
                    (JsonDeserializer<Date>) (jsonElement, type,
                            context) -> new Date(jsonElement.getAsJsonPrimitive().getAsLong()))
            .registerTypeAdapter(Date.class,
                    (JsonSerializer<Date>) (date, type,
                            jsonSerializationContext) -> new JsonPrimitive(date.getTime()))

            .create();/*from  w  ww. j a va2 s  .  co m*/
    String jsonInString = gson.toJson(positionEntity);

    RequestBody body = RequestBody.create(JSON, jsonInString);

    postRequestToApi(body);
    i++;
    return response;
}

From source file:com.adnanbal.fxdedektifi.forex.data.net.ApiConnection.java

License:Apache License

@Nullable
String request_putNewSignalSyncCall(NewPositionEntity newPositionEntity) {
    final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(Date.class,
                    (JsonDeserializer<Date>) (jsonElement, type,
                            context) -> new Date(jsonElement.getAsJsonPrimitive().getAsLong()))
            .registerTypeAdapter(Date.class,
                    (JsonSerializer<Date>) (date, type,
                            jsonSerializationContext) -> new JsonPrimitive(date.getTime()))

            .create();/*from   w ww. java2  s . co m*/
    String jsonInString = gson.toJson(newPositionEntity);

    RequestBody body = RequestBody.create(JSON, jsonInString);

    putRequestToApi(body);
    i++;
    return response;
}

From source file:com.adnanbal.fxdedektifi.forex.data.net.ApiConnection.java

License:Apache License

@Nullable
String request_patchSyncCall(Map<String, Boolean> userSignalMap) {
    final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(Date.class,
                    (JsonDeserializer<Date>) (jsonElement, type,
                            context) -> new Date(jsonElement.getAsJsonPrimitive().getAsLong()))
            .registerTypeAdapter(Date.class,
                    (JsonSerializer<Date>) (date, type,
                            jsonSerializationContext) -> new JsonPrimitive(date.getTime()))

            .create();/* www.  ja  va  2  s.  com*/
    String jsonInString = gson.toJson(userSignalMap);

    RequestBody body = RequestBody.create(JSON, jsonInString);

    patchRequestToApi(body);
    i++;
    return response;
}

From source file:com.adobe.acs.commons.audit_log_search.impl.AuditLogSearchServlet.java

License:Apache License

private JsonObject serializeAuditEvent(Resource auditEventResource, AuditLogSearchRequest request)
        throws RepositoryException, IOException, ClassNotFoundException {
    JsonObject auditEvent = new JsonObject();
    ValueMap properties = auditEventResource.getValueMap();
    auditEvent.addProperty("category", properties.get("cq:category", String.class));
    auditEvent.addProperty("eventPath", auditEventResource.getPath());
    auditEvent.addProperty("path", properties.get("cq:path", String.class));
    auditEvent.addProperty("type", properties.get("cq:type", String.class));
    String userId = properties.get("cq:userid", String.class);
    auditEvent.addProperty("userId", userId);
    auditEvent.addProperty("userName", request.getUserName(auditEventResource.getResourceResolver(), userId));
    auditEvent.addProperty("userPath", request.getUserPath(auditEventResource.getResourceResolver(), userId));
    auditEvent.addProperty("time", properties.get("cq:time", new Date()).getTime());

    JsonArray modified = getModifiedProperties(properties);
    if (properties.get("above", String.class) != null) {
        modified.add(new JsonPrimitive("above=" + properties.get("above", String.class)));
    }//  ww  w .j a  v  a  2s. c  o  m
    if (properties.get("destination", String.class) != null) {
        modified.add(new JsonPrimitive("destination=" + properties.get("destination", String.class)));
    }
    if (properties.get("versionId", String.class) != null) {
        modified.add(new JsonPrimitive("versionId=" + properties.get("versionId", String.class)));
    }
    if (modified.size() != 0) {
        auditEvent.add("modified", modified);
    }

    return auditEvent;
}

From source file:com.adobe.acs.commons.audit_log_search.impl.AuditLogSearchServlet.java

License:Apache License

@SuppressWarnings("unchecked")
private JsonArray getModifiedProperties(ValueMap properties) throws IOException {
    JsonArray modifiedProperties = new JsonArray();
    InputStream is = properties.get("cq:properties", InputStream.class);
    if (is != null) {
        ObjectInputStream ois = new ObjectInputStream(is);
        ois.readInt();//from  w w w .j  av a2 s.  co m

        while (ois.available() != -1) {
            try {
                Object obj = ois.readObject();
                if (obj instanceof HashSet) {
                    Set<String> propertiesSet = (Set<String>) obj;
                    for (String property : propertiesSet) {
                        modifiedProperties.add(new JsonPrimitive(property));
                    }
                    break;
                }
            } catch (Exception e) {
                break;
            }
        }
    }
    return modifiedProperties;
}

From source file:com.adobe.acs.commons.exporters.impl.users.UsersInitServlet.java

License:Apache License

/**
 * Creates a JSON array of the User Groups principals in the system.
 * @param resourceResolver the security context used to collect the groups.
 * @return a JSON Array of all the user group principals name that the resourceResolver can read.
 * @throws RepositoryException/*from  w  w w.  ja v a2 s . c om*/
 */
private JsonArray getGroupOptions(ResourceResolver resourceResolver) throws RepositoryException {
    final JsonArray jsonArray = new JsonArray();
    final QueryManager queryManager = resourceResolver.adaptTo(Session.class).getWorkspace().getQueryManager();
    final Query query = queryManager.createQuery(QUERY, Query.JCR_SQL2);
    final NodeIterator nodeIter = query.execute().getNodes();

    while (nodeIter.hasNext()) {
        Resource resource = resourceResolver.getResource(nodeIter.nextNode().getPath());
        jsonArray.add(new JsonPrimitive(resource.getValueMap().get("rep:principalName", "Unknown")));
    }

    return jsonArray;
}

From source file:com.adobe.acs.commons.wcm.impl.RTEConfigurationServlet.java

License:Apache License

private void writeConfigResource(Resource resource, String rteName, SlingHttpServletRequest request,
        SlingHttpServletResponse response) throws IOException, ServletException {
    JsonObject widget = createEmptyWidget(rteName);

    // these two size properties seem to be necessary to get the size correct
    // in a component dialog
    widget.addProperty("width", RTE_WIDTH);
    widget.addProperty("height", RTE_HEIGHT);

    RequestParameterMap map = request.getRequestParameterMap();
    for (Map.Entry<String, RequestParameter[]> entry : map.entrySet()) {
        String key = entry.getKey();
        RequestParameter[] params = entry.getValue();
        if (params != null && (params.length > 1 || EXTERNAL_STYLESHEETS_PROPERTY.equals(key))) {
            JsonArray arr = new JsonArray();
            for (int i = 0; i < params.length; i++) {
                arr.add(new JsonPrimitive(params[i].getString()));
            }/*from   w ww.  j  ava 2 s.  c  om*/
            widget.add(key, arr);
        } else if (params != null && params.length == 1) {
            widget.addProperty(key, params[0].getString());
        }
    }

    if (widget.has("fieldLabel")) {
        widget.remove("hideLabel");
    }

    JsonObject config = toJsonObject(resource);

    if (config == null) {
        config = new JsonObject();
    }

    if (config.has("includeDefault") && config.get("includeDefault").getAsBoolean()) {
        config = underlay(config, resource.getResourceResolver().getResource(DEFAULT_CONFIG));
    }

    widget.add("rtePlugins", config);

    JsonObject parent = new JsonObject();
    parent.addProperty("xtype", "dialogfieldset");
    parent.addProperty("border", false);
    parent.addProperty("padding", 0);
    parent.add("items", widget);
    Gson gson = new Gson();
    gson.toJson(parent, response.getWriter());
}