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:org.opendedup.sdfs.io.events.SFileDeleted.java

License:Open Source License

public String toJSON() {
    JsonObject dataset = this.toJSONObject();
    dataset.addProperty("actionType", "sfileDeleted");
    dataset.addProperty("object", this.sf.getGUID());
    Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls()
            .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create();
    return gson.toJson(dataset);
}

From source file:org.opendedup.sdfs.io.events.SFileWritten.java

License:Open Source License

public String toJSON() {
    JsonObject dataset = this.toJSONObject();
    dataset.addProperty("actionType", "sfileWritten");
    dataset.addProperty("volumeid", Long.toString(Main.DSEID));
    dataset.addProperty("timestamp", Long.toString(System.currentTimeMillis()));
    dataset.addProperty("object", sf.getGUID());
    Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls()
            .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create();
    return gson.toJson(dataset);
}

From source file:org.ramadda.repository.output.JsonOutputHandler.java

License:Apache License

/**
 * _more_// ww  w. j  a  v  a2 s .  c o m
 *
 * @param args _more_
 */
public static void main(String[] args) {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setPrettyPrinting();
    gsonBuilder.setDateFormat(DateFormat.LONG);
    gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE);

    Gson gson = gsonBuilder.create();
    Entry entry = new Entry();
    System.err.println(gson.toJson(entry));

}

From source file:org.rascalmpl.library.lang.json.IOCompiled.java

License:Open Source License

public IValue fromJSON(IValue type, IString src, RascalExecutionContext rex) {
    TypeStore store = new TypeStore();

    IConstructor type_cons = ((IConstructor) type);
    IMap definitions = rex.getSymbolDefinitions();

    tr.declareAbstractDataTypes(definitions, store);
    Type start = tr.valueToType(type_cons, store);

    //TypeStore store = ctx.getCurrentEnvt().getStore();
    //Type start = new TypeReifier(ctx.getValueFactory()).valueToType((IConstructor) type, store);

    //System.err.println("fromJSON0:"+start);
    Gson gson = new GsonBuilder().enableComplexMapKeySerialization().setDateFormat(DateFormat.LONG)
            .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).setVersion(1.0).create();
    //System.err.println("fromJSON1:"+src.getValue());
    Object obj = gson.fromJson(src.getValue(), Object.class);
    //System.err.println("fromJSON2:"+start);
    try {/* w ww.  j  a v  a 2s .  c  o  m*/
        return JSONReadingTypeVisitor.read(obj, values, store, start);
    } catch (IOException e) {
        throw RuntimeExceptionFactory.io(values.string(e.getMessage()), null, null);
    }
}

From source file:sintef.android.gravity.advanced.RecordFragment.java

License:Apache License

private void sendRecording() {
    sendRecordingSetViewParams();//w w w. j  a  v a2  s .c o  m

    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... voids) {
            JsonObject recordings = new JsonObject();

            String id = mTestIdInput.getText().toString();
            recordings.addProperty("test_id", id);

            JsonObject calculations = new JsonObject();

            JsonArray phoneVerticalAcceleration = new JsonArray();
            JsonArray phoneTotalAcceleration = new JsonArray();
            JsonArray watchFallIndex = new JsonArray();
            JsonArray watchDirectionAcceleration = new JsonArray();
            JsonArray watchAfterFall = new JsonArray();

            for (RecordEventData entry : mRecordEvents) {
                JsonObject object = new JsonObject();
                object.addProperty("time", entry.time);
                object.addProperty("value", entry.value);

                switch (entry.type) {
                case RECORDING_PHONE_VERTICAL_ACCELERATION:
                    phoneVerticalAcceleration.add(object);
                    break;
                case RECORDING_PHONE_TOTAL_ACCELERATION:
                    phoneTotalAcceleration.add(object);
                    break;
                case RECORDING_WATCH_FALL_INDEX:
                    watchFallIndex.add(object);
                    break;
                case RECORDING_WATCH_DIRECTION_ACCELERATION:
                    watchDirectionAcceleration.add(object);
                    break;
                case RECORDING_WATCH_AFTER_FALL:
                    watchAfterFall.add(object);
                    break;
                }
            }

            calculations.add("phone_vertical_acceleration", phoneVerticalAcceleration);
            calculations.add("phone_total_acceleration", phoneTotalAcceleration);
            calculations.add("watch_fall_index", watchFallIndex);
            calculations.add("watch_direction_acceleration", watchDirectionAcceleration);
            calculations.add("watch_after_fall", watchAfterFall);

            recordings.add("calculations", calculations);

            /*
            JsonArray recordEvents = new JsonArray();
                    
            for (RecordEvent event : mRecordEvents) {
            JsonObject accelerometerObject = new JsonObject();
            accelerometerObject.addProperty("vertical_acceleration", event.mVerAcc);
            accelerometerObject.addProperty("total_acceleration", event.mTotAcc);
            recordEvents.add(accelerometerObject);
            }
                    
            recordings.add("record_data", recordEvents);
            */

            Collections.sort(mRecordAlgorithm);
            JsonArray fallDetectedArray = new JsonArray();
            for (RecordAlgorithmData algorithmData : mRecordAlgorithm) {
                JsonObject fallDetectedObject = new JsonObject();
                fallDetectedObject.addProperty("id", algorithmData.id);
                fallDetectedObject.addProperty("time", algorithmData.time);
                fallDetectedObject.addProperty("name", algorithmData.name);
                fallDetectedObject.addProperty("isFall", algorithmData.isFall);
                fallDetectedArray.add(fallDetectedObject);
            }
            recordings.add("fall_detection", fallDetectedArray);

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

            final String ip = mServerIp.getText().toString();
            final String port = mServerPort.getText().toString();
            PreferencesHelper.putString(SERVER_IP, ip);
            PreferencesHelper.putString(SERVER_PORT, port);

            final String jsonData = gson.toJson(recordings);
            RecordHistoryFragment.saveJSONDataToDisk(id, jsonData);

            try {
                Socket socket = new Socket(ip, Integer.valueOf(port));
                socket.setSoTimeout(10000);
                DataOutputStream DOS = null;
                DOS.writeBytes(jsonData);
                socket.close();
                if (mActivity != null)
                    mActivity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(getActivity(), "Sensor data sent to server " + ip + ":" + port,
                                    Toast.LENGTH_SHORT).show();
                        }
                    });
                else
                    Log.w("Record", "activity is null");
            } catch (Exception e) {
                e.printStackTrace();
                if (mActivity != null)
                    mActivity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(getActivity(), "Sensor data failed to send to " + ip + ":" + port,
                                    Toast.LENGTH_SHORT).show();
                        }
                    });
                else
                    Log.w("Record", "activity is null");
            }
            return null;
        }
    }.execute();
}