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:com.readystatesoftware.chuck.internal.support.JsonConvertor.java

License:Apache License

public static Gson getInstance() {
    if (gson == null) {
        gson = new GsonBuilder().setPrettyPrinting()
                .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
                .registerTypeAdapter(Date.class, new DateTypeAdapter()).create();
    }/* w w  w  .j av a2  s .c  om*/
    return gson;
}

From source file:com.sangupta.clitools.facebook.FacebookInfo.java

License:Apache License

@Override
public void run() {
    if (AssertUtils.isEmpty(this.account)) {
        System.out.println("Account or page name is required.");
        return;/* w ww. j av a2  s.c  o m*/
    }

    String url = "https://graph.facebook.com/" + this.account.toLowerCase();
    WebResponse response = WebInvoker.getResponse(url);
    if (response == null) {
        System.out.println("Unable to fetch response from server");
        return;
    }

    if (!response.isSuccess()) {
        System.out.println("Non-success response from server as: " + response.trace());
        System.out.println("May be user/page does not exist!");
        return;
    }

    FacebookInfoResponse info = GsonUtils.getGson(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
            .fromJson(response.getContent(), FacebookInfoResponse.class);

    // start display

    ConsoleTable table = new ConsoleTable(ConsoleTableLayout.MULTI_LINE);
    table.setColumnSeparator("  ");
    table.addRow("User Name", nonNull(info.username));
    table.addRow("ID", nonNull(info.id));
    table.addRow("Name", nonNull(info.name));
    table.addRow("Link", nonNull(info.link));
    table.addRow("Website", nonNull(info.website));
    table.addRow("Talking About", info.talkingAboutCount);
    table.addRow("Likes", info.likes);
    table.addRow("Bio", nonNull(info.bio));
    table.addRow("About", nonNull(info.about));
    table.addRow("Category", nonNull(info.category));
    table.addRow("Hometown", nonNull(info.hometown));

    table.write(System.out);
}

From source file:com.sangupta.satya.client.impl.DropBoxAuthClient.java

License:Apache License

@Override
protected FieldNamingPolicy getFieldNamingPolicy() {
    return FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES;
}

From source file:com.sangupta.socialcount.SocialCountClient.java

License:Apache License

/**
 * Find the facebook shares for a given URL.
 * /*w w  w  . jav  a 2  s  .co m*/
 * Refer <a
 * href="https://developers.facebook.com/docs/reference/fql/link_stat/">
 * https://developers.facebook.com/docs/reference/fql/link_stat/</a> for
 * more details.
 * 
 * @param counts
 *            the {@link SocialCounts} instance to be updated and containing
 *            the url
 */
public static void getFacebookCount(SocialCounts counts) {
    String query = "SELECT url, like_count, click_count, comment_count, share_count FROM link_stat WHERE url='"
            + counts.url + "'";
    String api = "http://graph.facebook.com/fql?q=" + UriUtils.encodeURIComponent(query);
    WebResponse response = WebInvoker.getResponse(api);
    if (response == null || !response.isSuccess()) {
        return;
    }

    FacebookResponse facebook = GsonUtils.getGson(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
            .fromJson(response.getContent(), FacebookResponse.class);
    if (facebook == null || facebook.data == null) {
        return;
    }

    counts.facebookShares = facebook.data[0].shareCount;
    counts.facebookComments = facebook.data[0].commentCount;
    counts.facebookLikes = facebook.data[0].likeCount;
    counts.facebookClicks = facebook.data[0].clickCount;
}

From source file:com.sangupta.twittercli.command.Follow.java

License:Apache License

@Override
public void doCommand() {
    for (String user : users) {
        WebRequest request = WebInvoker.getWebRequest(
                "https://api.twitter.com/1.1/friendships/create.json?screen_name=" + getScreenName(user),
                WebRequestMethod.POST);//from   w  w  w.  j a  va2 s  .c  o m
        super.user.signRequest(request);
        WebResponse response = WebInvoker.executeSilently(request);
        if (response == null || !response.isSuccess()) {
            System.out.println("Unable to follow user: " + user);
        }

        TwitterUserProfile profile = GsonUtils.getGson(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
                .fromJson(response.getContent(), TwitterUserProfile.class);
        System.out.println("Successfully followed user: " + profile.getName() + " (" + user + ")");
    }
}

From source file:com.sangupta.twittercli.command.Followers.java

License:Apache License

@Override
public void doCommand() {
    List<TwitterUserProfile> userList = new ArrayList<TwitterUserProfile>();

    long cursor = -1;
    do {//from w  ww. jav a2s.  c  o m
        WebRequest request = WebInvoker.getWebRequest(
                "https://api.twitter.com/1.1/followers/list.json?count=200&cursor=" + cursor,
                WebRequestMethod.GET);
        user.signRequest(request);
        WebResponse response = WebInvoker.executeSilently(request);
        TwitterUserList list = GsonUtils.getGson(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
                .fromJson(response.getContent(), TwitterUserList.class);

        if (list != null) {
            userList.addAll(Arrays.asList(list.users));
        }

        if (list.nextCursor == 0) {
            break;
        }
        cursor = list.nextCursor;
    } while (true);

    ConsoleTable table = new ConsoleTable(ConsoleTableLayout.MULTI_LINE);
    table.addHeaderRow("S.No.", "Screen Name", "Full Name", "Bio");

    int count = 1;
    for (TwitterUserProfile profile : userList) {
        table.addRow(count++, profile.getScreenName(), profile.getName(), profile.getDescription());
    }

    table.setColumnSize(1, 15);
    table.setColumnSize(2, 25);
    table.setColumnSize(3, 40);

    table.write(System.out);
}

From source file:com.sangupta.twittercli.command.Following.java

License:Apache License

@Override
public void doCommand() {
    List<TwitterUserProfile> userList = new ArrayList<TwitterUserProfile>();

    long cursor = -1;
    do {/*from   www  .j av a2  s.  c o m*/
        WebRequest request = WebInvoker.getWebRequest(
                "https://api.twitter.com/1.1/friends/list.json?count=200&cursor=" + cursor,
                WebRequestMethod.GET);
        user.signRequest(request);
        WebResponse response = WebInvoker.executeSilently(request);
        TwitterUserList list = GsonUtils.getGson(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
                .fromJson(response.getContent(), TwitterUserList.class);

        if (list != null) {
            userList.addAll(Arrays.asList(list.users));
        }

        if (list.nextCursor == 0) {
            break;
        }
        cursor = list.nextCursor;
    } while (true);

    ConsoleTable table = new ConsoleTable(ConsoleTableLayout.MULTI_LINE);
    table.addHeaderRow("S.No.", "Screen Name", "Full Name", "Bio");

    int count = 1;
    for (TwitterUserProfile profile : userList) {
        table.addRow(count++, profile.getScreenName(), profile.getName(), profile.getDescription());
    }

    table.setColumnSize(1, 15);
    table.setColumnSize(2, 25);
    table.setColumnSize(3, 40);

    table.write(System.out);
}

From source file:com.sangupta.twittercli.command.Mentions.java

License:Apache License

@Override
public void doCommand() {
    WebRequest request = WebInvoker.getWebRequest("https://api.twitter.com/1.1/statuses/mentions_timeline.json",
            WebRequestMethod.GET);//from www.j a v  a2  s .  c o m
    user.signRequest(request);
    WebResponse response = WebInvoker.executeSilently(request);
    TwitterStatusUpdate[] updates = GsonUtils.getGson(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
            .fromJson(response.getContent(), TwitterStatusUpdate[].class);

    if (AssertUtils.isEmpty(updates)) {
        System.out.println("No mentions found");
        return;
    }

    System.out.println();
    for (TwitterStatusUpdate update : updates) {
        System.out.println("  @" + update.user.getScreenName());
        System.out.println("  " + update.text);
        System.out.println("  " + update.createdAt);
        System.out.println();
    }
}

From source file:com.sangupta.twittercli.command.Retweets.java

License:Apache License

@Override
public void doCommand() {
    WebRequest request = WebInvoker.getWebRequest("https://api.twitter.com/1.1/statuses/retweets_of_me.json",
            WebRequestMethod.GET);/*from w w w.ja v  a2  s .  c  om*/
    user.signRequest(request);
    WebResponse response = WebInvoker.executeSilently(request);
    TwitterStatusUpdate[] updates = GsonUtils.getGson(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
            .fromJson(response.getContent(), TwitterStatusUpdate[].class);

    if (AssertUtils.isEmpty(updates)) {
        System.out.println("No retweets found");
        return;
    }

    for (TwitterStatusUpdate update : updates) {
        System.out.println("  @" + update.user.getScreenName());
        System.out.println("  " + update.text);
        System.out.println("  " + update.createdAt);
        System.out.println();
    }
}

From source file:com.sangupta.twittercli.command.RetweetsOfMe.java

License:Apache License

@Override
public void doCommand() {
    WebRequest request = WebInvoker.getWebRequest("https://api.twitter.com/1.1/statuses/retweets_of_me.json",
            WebRequestMethod.GET);/*from   w  w  w .  ja va2 s .c  om*/
    user.signRequest(request);
    WebResponse response = WebInvoker.executeSilently(request);
    TwitterStatusUpdate[] updates = GsonUtils.getGson(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
            .fromJson(response.getContent(), TwitterStatusUpdate[].class);

    if (AssertUtils.isEmpty(updates)) {
        System.out.println("No retweets found");
        return;
    }

    System.out.println();
    for (TwitterStatusUpdate update : updates) {
        System.out.println("  @" + update.user.getScreenName());
        System.out.println("  " + update.text);
        System.out.println("  " + update.createdAt);
        System.out.println();
    }
}