Example usage for com.google.gson FieldNamingPolicy UPPER_CAMEL_CASE

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

Introduction

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

Prototype

FieldNamingPolicy UPPER_CAMEL_CASE

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

Click Source Link

Document

Using this naming policy with Gson will ensure that the first "letter" of the Java field name is capitalized when serialized to its JSON form.

Usage

From source file:com.amazonaws.reactnative.sns.AWSRNSNSClient.java

License:Open Source License

@ReactMethod
public void initWithOptions(final ReadableMap options) {
    if (!options.hasKey("region")) {
        throw new IllegalArgumentException("expected region key");
    }/*from w  w  w. ja va  2  s . c  om*/
    final AWSRNCognitoCredentials credentials = this.getReactApplicationContext()
            .getNativeModule(AWSRNCognitoCredentials.class);
    if (credentials.getCredentialsProvider() == null) {
        throw new IllegalArgumentException("AWSCognitoCredentials is not initialized");
    }
    gson = new GsonBuilder().setFieldNamingStrategy(FieldNamingPolicy.UPPER_CAMEL_CASE)
            .registerTypeAdapter(ByteBuffer.class, AWSRNClientMarshaller.getSerializer())
            .registerTypeAdapter(ByteBuffer.class, AWSRNClientMarshaller.getDeserializer()).create();
    snsClient = new AmazonSNSClient(credentials.getCredentialsProvider(),
            new AWSRNClientConfiguration().withUserAgent("SNS"));
    snsClient.setRegion(Region.getRegion(Regions.fromName(options.getString("region"))));
}

From source file:com.bosch.osmi.bdp.access.mock.generator.MockDataGenerator.java

License:Open Source License

private void writeToJsonFile(JsonObject resultStore) throws IOException {
    String path = Util.getHomeDir() + File.separator + ".bdp-access-files" + File.separator + "mockdata.json";
    File file = new File(path);
    boolean dirCreated = file.getParentFile().mkdirs();
    if (dirCreated) {
        LOGGER.debug("Unable to create directory " + file.getParentFile().getAbsolutePath()
                + ". Maybe it already exists.");
    }/* www  .  j a va2 s .  com*/

    try (Writer writer = new FileWriter(file)) {
        Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls()
                .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create();
        gson.toJson(resultStore, writer);
    }
}

From source file:com.dabay6.android.apps.carlog.app.InitializationIntentService.java

License:Open Source License

/**
 * @return/*from  w w  w .j a  v  a  2s.co m*/
 */
private Gson buildGson() {
    final GsonBuilder builder = new GsonBuilder();

    builder.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE);

    return builder.create();
}

From source file:com.example.app.support.FormProcessJsonUtil.java

License:Open Source License

/**
 * Convert the FormProcess to JSON.//from w w  w. j a va 2  s. c o  m
 *
 * @param formProcess the form process
 * @param context Optional context section for the JSON document.
 * @param lc the locale context
 *
 * @return json
 */
public static JsonObject toJSON(FormProcess formProcess, JsonObject context, LocaleContext lc) {
    final DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");

    JsonObject form = new JsonObject();
    form.addProperty("programmaticIdentifier",
            formProcess.getFormRevision().getFormDefinition().getProgrammaticIdentifier());
    form.addProperty("status", formProcess.getState().name());
    form.addProperty("submitTime",
            formProcess.getSubmitTime() == null ? null : sdf.format(formProcess.getSubmitTime()));
    form.addProperty("createTime", sdf.format(formProcess.getCreateTime()));

    JsonObject answers = new JsonObject();
    form.add("answers", answers);

    final EntityRetriever et = EntityRetriever.getInstance();
    final FormData formData = FormProcessUtil.getInstance().getFormData(formProcess, true);
    for (ExtraValue evl : formData.getExtraValueList().getExtraValues()) {
        evl = et.narrowProxyIfPossible(evl);

        JsonObject answer = new JsonObject();

        Extra e = et.narrowProxyIfPossible(evl.getExtra());

        answers.add(e.getProgrammaticName(), answer);
        if (e.getName() != null)
            answer.addProperty("name", e.getName().getText(lc).toString());
        if (e.getShortName() != null)
            answer.addProperty("shortName", e.getShortName().getText(lc).toString());
        answer.addProperty("type", e.getClass().getSimpleName().replace("Extra", ""));
        answer.addProperty("answer", evl.getAsText(lc).toString());

        if (evl instanceof ChoiceExtraValue) {
            ChoiceExtraValue cev = (ChoiceExtraValue) evl;
            ChoiceExtra choiceExtra = (ChoiceExtra) e;

            if (choiceExtra.isAllowMultipleChoice()) {
                JsonArray programmatic = new JsonArray();
                for (ChoiceExtraChoice choice : cev.getChoices()) {
                    JsonObject c = new JsonObject();
                    c.addProperty("name", choice.getName().getText(lc).toString());
                    c.addProperty("programmaticName", choice.getProgrammaticName());
                    if (!StringFactory.isEmptyString(choice.getReportValue()))
                        c.addProperty("reportValue", choice.getReportValue());
                    ChoiceTextValue choiceTextValue = cev.getChoiceTextValue(choice);
                    if (choiceTextValue != null)
                        c.addProperty("userText", choiceTextValue.getValue());
                    programmatic.add(c);
                }
                answer.add("programmatic", programmatic);
            } else {
                JsonObject c = new JsonObject();
                ChoiceExtraChoice choice = cev.getChoices().isEmpty() ? null : cev.getChoices().get(0);
                if (choice != null) {
                    c.addProperty("name", choice.getName().getText(lc).toString());
                    c.addProperty("programmaticName", choice.getProgrammaticName());
                    if (!StringFactory.isEmptyString(choice.getReportValue()))
                        c.addProperty("reportValue", choice.getReportValue());
                    ChoiceTextValue choiceTextValue = cev.getChoiceTextValue(choice);
                    if (choiceTextValue != null)
                        c.addProperty("userText", choiceTextValue.getValue());
                }
                answer.add("programmatic", c);
            }
        } else {
            Map<Enum<?>, Object> programmaticValueParts = evl.getProgrammaticValueParts();
            if (!programmaticValueParts.isEmpty()) {
                JsonArray programmatic = new JsonArray();

                for (Map.Entry<Enum<?>, Object> entry : programmaticValueParts.entrySet()) {
                    JsonObject c = new JsonObject();
                    programmatic.add(c);

                    c.addProperty("part", entry.getKey().name());
                    c.addProperty("value", entry.getValue() != null ? entry.getValue().toString() : null);
                }

                answer.add("programmatic", programmatic);
            }
        }
    }

    JsonObject json = new JsonObject();
    json.add("form", form);
    if (context != null)
        json.add("context", context);

    if (_logger.isTraceEnabled()) {
        Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls()
                .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create();
        _logger.trace(gson.toJson(json));
    }

    return json;
}

From source file:com.expensify.testframework.SubmitResultContainer.java

License:Microsoft Public License

public static String RawStringify(ResultBase result) {
    GsonBuilder gsonBuilder = new GsonBuilder();
    Gson gson = gsonBuilder.create();// www.j a va  2 s  .c  om
    gsonBuilder.serializeNulls();
    gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE);
    gsonBuilder.disableHtmlEscaping();
    gsonBuilder.registerTypeHierarchyAdapter(ResultBase.class, new ResultSerializer());
    String resultJson = gson.toJson(result);
    resultJson = hackResultJsonOrder(resultJson);
    return resultJson;
}

From source file:com.expensify.testframework.utils.CommandDeserializer.java

License:Microsoft Public License

public CommandDeserializer(String commandElementName) {
    this.commandElementName = commandElementName;
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE);
    gson = gsonBuilder.create();/*  ww  w .j a  v a2s .  c  o m*/
    commandRegistry = new HashMap<String, Class<? extends CommandBase>>();
}

From source file:com.google.code.bing.search.client.impl.BingSearchJsonClientImpl.java

License:Apache License

/**
 * Gets the gson builder./*from w  w w.ja v a2  s .c  om*/
 * 
 * @return the gson builder
 */
protected GsonBuilder getGsonBuilder() {
    GsonBuilder builder = new GsonBuilder();
    builder.setDateFormat(ApplicationConstants.DATE_FORMAT);
    builder.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE);
    //      builder.registerTypeAdapter(Issue.State.class, new JsonDeserializer<Issue.State>() {
    //         @Override
    //         public Issue.State deserialize(JsonElement arg0, Type arg1,
    //               JsonDeserializationContext arg2) throws JsonParseException {
    //            return Issue.State.fromValue(arg0.getAsString());
    //         }
    //      });
    return builder;
}

From source file:com.saspes.rest.Utils.java

public static String messageJosn(MessageTags message, String messageText) {
    DateFormat df = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
    Date date = new Date();

    JsonObject messageJson = new JsonObject();
    messageJson.addProperty(message.name().toLowerCase(), messageText);
    messageJson.addProperty("time", df.format(date));

    Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls()
            .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create();
    return gson.toJson(messageJson);
}

From source file:com.xebia.xsdnl.innorater.server.Servers.java

License:Creative Commons License

public static RaterService raterService() {
    if (raterService == null) {
        OkHttpClient okHttpClient = new OkHttpClient();

        Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create();

        final String userAgent = buildUserAgent();
        RequestInterceptor standardHeaders = new RequestInterceptor() {
            @Override//from   w  w w  .j ava  2 s.  c o  m
            public void intercept(RequestFacade request) {
                // For response compression, AppEngine requires the Accept-Encoding header that
                // OkHTTP adds automatically *and* the string "gzip" as part of the User-Agent.
                request.addHeader("User-Agent", userAgent);
                request.addHeader("Accept", "application/json");
            }
        };

        RestAdapter restAdapter = new RestAdapter.Builder().setClient(new OkClient(okHttpClient))
                .setEndpoint("https://xebia-innovation-day-rater.appspot.com")
                .setLogLevel(RestAdapter.LogLevel.FULL).setConverter(new GsonConverter(gson))
                .setRequestInterceptor(standardHeaders).build();

        raterService = restAdapter.create(RaterService.class);
    }
    return raterService;
}

From source file:dealRetriever.HUKD.java

public String returnJson() {
    Gson gson = new GsonBuilder().setPrettyPrinting().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
            .create();//w  w  w.  j  a va  2  s .  com
    String json = gson.toJson(this);
    return json;
}