Example usage for com.google.gson FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES

List of usage examples for com.google.gson FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES

Introduction

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

Prototype

FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES

To view the source code for com.google.gson FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES.

Click Source Link

Document

Using this naming policy with Gson will modify the Java Field name from its camel cased form to a lower case field name where each word is separated by an underscore (_).

Usage

From source file:hu.vitamas.enotesz.controller.UserSettingsController.java

License:Apache License

private SimpleApiResponse sendDeleteRequest() {

    String apiKey = Core.getApiKey();
    String apiLink = Core.getApiBaseUrl();
    String pass = deletePasswordField.getText();
    Integer id = Auth.getUserID();

    if (apiKey == null || apiLink == null)
        return null;

    HashMap<String, String> params = MapBuilder.<String, String>newHashMap().set("userid", id.toString())
            .set("password", pass).set("apiKey", apiKey).build();

    try {//from w  w w  .  j  a  va2  s. c  o  m
        String response = Core.createApi().setMethod("POST").setUrl(apiLink + "user/deleteAccount")
                .setParams(params).sendRequest();
        if (response == null)
            return null;
        Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
                .create();
        return gson.fromJson(response, SimpleApiResponse.class);
    } catch (Exception e) {
        logger.error("api or gson error", e);
    }

    return null;
}

From source file:hu.vitamas.enotesz.util.Auth.java

License:Apache License

/**
 * Checks the user is logged in or not./*from w w w.  j av  a 2s.com*/
 * 
 * <p>This method communicate with the eNotesz server.
 * <p><b>Must to send API request because of encryption.</b>
 * 
 * @param name name of user
 * @param password password of user
 * @return AuthResponse
 */
public static AuthResponse check(String name, String password) {
    String apiKey = Core.getApiKey();
    String apiLink = Core.getApiBaseUrl();

    if (apiKey == null || apiLink == null)
        return null;

    HashMap<String, String> params = MapBuilder.<String, String>newHashMap().set("pass", password)
            .set("name", name).set("apiKey", apiKey).build();

    try {
        String response = Core.createApi().setMethod("POST").setUrl(apiLink + "user/checkUser")
                .setParams(params).sendRequest();
        if (response == null)
            return null;
        Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
                .create();
        return gson.fromJson(response, AuthResponse.class);
    } catch (Exception e) {
        logger.error("api or gson error", e);
    }

    return null;
}

From source file:id.zelory.benih.util.Bson.java

License:Apache License

Bson() {
    parser = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
            .setPrettyPrinting().registerTypeAdapter(Date.class, new DateTypeAdapter()).create();
}

From source file:io.kamax.mxisd.backend.rest.RestProvider.java

License:Open Source License

public RestProvider(RestBackendConfig cfg) {
    this.cfg = cfg;

    client = HttpClients.createDefault();
    gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
    parser = new GsonParser(gson);
}

From source file:io.kamax.mxisd.util.GsonParser.java

License:Open Source License

public GsonParser() {
    this(new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create());
}

From source file:io.kamax.mxisd.util.GsonUtil.java

License:Open Source License

public static Gson build() {
    return new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
}

From source file:io.seqware.pipeline.engines.whitestar.Persistence.java

License:Open Source License

public synchronized SortedSet<String> readCompletedJobs() {
    try {// w ww.jav  a 2  s.c o m
        Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
                .setPrettyPrinting().create();
        String statesString = FileUtils.readFileToString(new File(persistDir, STATE_FILENAME));
        Type collectionType = new TypeToken<SortedSet<String>>() {
        }.getType();
        SortedSet<String> states = gson.fromJson(statesString, collectionType);
        return states;
    } catch (IOException ex) {
        Log.stdoutWithTime("Unable to read workflowrun state");
        rethrow(ex);
    }
    return null;
}

From source file:io.seqware.pipeline.engines.whitestar.Persistence.java

License:Open Source License

public synchronized WorkflowRun readWorkflowRun() {
    try {//w  ww .j  a v a  2 s . co  m
        Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
                .setPrettyPrinting().create();
        String workflowRunString = FileUtils.readFileToString(new File(persistDir, WORKFLOW_RUN_FILENAME));
        String workflowString = FileUtils.readFileToString(new File(persistDir, WORKFLOW_FILENAME));
        WorkflowRun workflowRun = gson.fromJson(workflowRunString, WorkflowRun.class);
        Workflow workflow = gson.fromJson(workflowString, Workflow.class);
        workflowRun.setWorkflow(workflow);
        SortedSet<WorkflowRun> runs = new TreeSet<>();
        runs.add(workflowRun);
        workflow.setWorkflowRuns(runs);
        // load into persistence store if needed
        Metadata metadata = MetadataFactory.get(ConfigTools.getSettings());
        if (metadata instanceof MetadataInMemory) {
            MetadataInMemory mim = (MetadataInMemory) metadata;
            mim.loadEntity(workflow);
            mim.loadEntity(workflowRun);
        }
        return workflowRun;
    } catch (IOException ex) {
        Log.stdoutWithTime("Unable to read workflowrun state");
        rethrow(ex);
    }
    return null;
}

From source file:io.seqware.pipeline.engines.whitestar.Persistence.java

License:Open Source License

public synchronized void persistState(int swid, SortedSet<String> completedJobs) {
    try {/*from w  w w.  ja  v a 2 s . co m*/
        // write state of workflow run
        Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
                .setPrettyPrinting().create();
        Metadata ws = MetadataFactory.get(ConfigTools.getSettings());
        WorkflowRun workflowRun = ws.getWorkflowRunWithWorkflow(String.valueOf(swid));
        Workflow workflow = workflowRun.getWorkflow();
        workflowRun.setWorkflow(null);
        workflow.setWorkflowRuns(null);
        if (workflow.getWorkflowParams() != null) {
            for (WorkflowParam param : workflow.getWorkflowParams()) {
                param.setWorkflow(null);
            }
        }
        // ugly, need to avoid circular reference before serialization
        FileUtils.write(new File(persistDir, WORKFLOW_RUN_FILENAME), gson.toJson(workflowRun));
        FileUtils.write(new File(persistDir, WORKFLOW_FILENAME), gson.toJson(workflow));
        FileUtils.write(new File(persistDir, STATE_FILENAME), gson.toJson(completedJobs));
        workflowRun.setWorkflow(workflow);
        SortedSet<WorkflowRun> set = new TreeSet<>();
        set.add(workflowRun);
        workflow.setWorkflowRuns(set);
        if (workflow.getWorkflowParams() != null) {
            for (WorkflowParam param : workflow.getWorkflowParams()) {
                param.setWorkflow(workflow);
            }
        }
    } catch (IOException ex) {
        Log.stdoutWithTime("Unable to write workflowrun state");
        rethrow(ex);
    }
}

From source file:io.soramitsu.iroha.api.IrohaClient.java

License:Open Source License

private IrohaClient() {
    Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
            .registerTypeAdapter(Date.class, new DateTypeAdapter()).create();

    irohaService = new Retrofit.Builder().baseUrl("https://point-demo.iroha.tech/")
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create(gson)).build().create(IrohaService.class);
}