Example usage for com.google.gson GsonBuilder setPrettyPrinting

List of usage examples for com.google.gson GsonBuilder setPrettyPrinting

Introduction

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

Prototype

public GsonBuilder setPrettyPrinting() 

Source Link

Document

Configures Gson to output Json that fits in a page for pretty printing.

Usage

From source file:org.eclipse.packagedrone.repo.channel.impl.ChannelInstanceModelProvider.java

License:Open Source License

private static Gson createGson() {
    final GsonBuilder builder = new GsonBuilder();
    builder.setPrettyPrinting();
    builder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    return builder.create();
}

From source file:org.eclipse.packagedrone.repo.channel.impl.ChannelServiceModelProvider.java

License:Open Source License

protected Gson createGson() {
    final GsonBuilder builder = new GsonBuilder();
    builder.setPrettyPrinting();
    builder.serializeNulls();/*from ww w. ja  v  a 2 s.  c o  m*/
    builder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    builder.registerTypeAdapter(DeployGroup.class, new DeployGroupTypeAdapter());
    builder.registerTypeAdapter(MetaKey.class, MetaKeyTypeAdapter.INSTANCE);
    return builder.create();
}

From source file:org.eclipse.packagedrone.storage.apm.AbstractSimpleGsonStorageModelProvider.java

License:Open Source License

protected Gson createGson() {
    final GsonBuilder gb = new GsonBuilder();

    gb.setPrettyPrinting();
    gb.registerTypeAdapter(Instant.class, InstantTypeAdapter.DEFAULT_INSTANCE);

    return gb.create();
}

From source file:org.eclipse.recommenders.utils.gson.GsonUtil.java

License:Open Source License

public static synchronized Gson getInstance() {
    if (gson == null) {
        final GsonBuilder builder = new GsonBuilder();

        builder.registerTypeAdapter(VmMethodName.class, new MethodNameTypeAdapter());
        builder.registerTypeAdapter(IMethodName.class, new MethodNameTypeAdapter());

        builder.registerTypeAdapter(VmTypeName.class, new TypeNameTypeAdapter());
        builder.registerTypeAdapter(ITypeName.class, new TypeNameTypeAdapter());

        builder.registerTypeAdapter(VmFieldName.class, new FieldNameTypeAdapter());
        builder.registerTypeAdapter(IFieldName.class, new FieldNameTypeAdapter());

        builder.registerTypeAdapter(VmPackageName.class, new PackageNameTypeAdapter());
        builder.registerTypeAdapter(IPackageName.class, new PackageNameTypeAdapter());

        builder.registerTypeAdapter(File.class, new FileTypeAdapter());

        builder.registerTypeAdapter(UUID.class, new UuidTypeAdapter());

        builder.registerTypeAdapter(Date.class, new ISO8601DateParser());

        builder.registerTypeAdapter(Multimap.class, new MultimapTypeAdapter());

        builder.registerTypeAdapterFactory(new MultisetTypeAdapterFactory());

        builder.enableComplexMapKeySerialization();
        builder.setPrettyPrinting();
        gson = builder.create();/*from  w  ww. ja v a2 s.c o  m*/
    }
    return gson;
}

From source file:org.helios.apmrouter.dataservice.json.marshalling.GSONJSONMarshaller.java

License:Open Source License

/**
 * Creates a new Gson instance based on the settings in this bean.
 *//*from   w  w  w .  j a va  2s.c o  m*/
protected void update() {
    GsonBuilder builder = new GsonBuilder();
    if (prettyPrint)
        builder.setPrettyPrinting();
    if (disableHtmlEscaping)
        builder.disableHtmlEscaping();
    if (!adapterInstances.isEmpty()) {
        for (Map.Entry<Type, Object> entry : adapterInstances.entrySet()) {
            builder.registerTypeAdapter(entry.getKey(), entry.getValue());
        }
    }
    if (!adapterFactoryInstances.isEmpty()) {
        for (TypeAdapterFactory taf : adapterFactoryInstances) {
            builder.registerTypeAdapterFactory(taf);
        }
    }
    gson = builder.create();
}

From source file:org.hibernate.search.backend.elasticsearch.gson.impl.JsonLogHelper.java

License:LGPL

public static JsonLogHelper create(GsonBuilder gsonBuilder, boolean prettyPrinting) {
    if (prettyPrinting) {
        gsonBuilder.setPrettyPrinting();
    }/*from  w  ww. j  ava 2  s. c  o  m*/
    return new JsonLogHelper(gsonBuilder.create(), prettyPrinting);
}

From source file:org.ihtsdo.runner.ProcessRunner.java

License:Apache License

/**
 * Gets the params.//from   w  w  w .  j  av  a2  s  .c o m
 *
 * @param file the file
 * @return the params
 * @throws ClassNotFoundException the class not found exception
 */
private void getParams(File file) throws ClassNotFoundException {

    logger.info("Paramaters in " + file.getAbsolutePath());
    config = XmlMapUtil.getConfigFromFileSystem(file);
    GsonBuilder gsonb = new GsonBuilder();
    gsonb.setPrettyPrinting();
    Gson gson = gsonb.create();
    logger.info(gson.toJson(config, Class.forName("org.ihtsdo.configuration.Parameters")));

    specialCpts = new ArrayList<String>();
    specialCpts.add(I_Constants.DUPLICATE_CONCEPT);
    specialCpts.add(I_Constants.AMBIGUOUS_CONCEPT);
    specialCpts.add(I_Constants.OUTDATED_CONCEPT);
    specialCpts.add(I_Constants.ERRONEOUS_CONCEPT);
    specialCpts.add(I_Constants.LIMITED_CONCEPT);
    specialCpts.add(I_Constants.MOVED_ELSEWHERE_CONCEPT);
    specialCpts.add(I_Constants.REASON_NOT_STATED_CONCEPT);
}

From source file:org.jenkinsci.plugins.bitbucket.BitbucketBuildStatusHelper.java

License:Open Source License

public static void sendBuildStatusNotification(final UsernamePasswordCredentials credentials,
        final Run<?, ?> build, final BitbucketBuildStatusResource buildStatusResource,
        final BitbucketBuildStatus buildStatus, final TaskListener listener) throws Exception {
    if (credentials == null) {
        throw new Exception("Credentials could not be found!");
    }/*from   w w w  .j ava  2s.co m*/

    OAuthConfig config = new OAuthConfig(credentials.getUsername(), credentials.getPassword().getPlainText());
    BitbucketApiService apiService = (BitbucketApiService) new BitbucketApi().createService(config);

    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeAdapter(BitbucketBuildStatus.class, new BitbucketBuildStatusSerializer());
    gsonBuilder.setPrettyPrinting();
    Gson gson = gsonBuilder.create();

    OAuthRequest request = new OAuthRequest(Verb.POST, buildStatusResource.generateUrl(Verb.POST));
    request.addHeader("Content-type", "application/json");
    request.addPayload(gson.toJson(buildStatus));

    Token token = apiService.getAccessToken(OAuthConstants.EMPTY_TOKEN, null);
    apiService.signRequest(token, request);

    Response response = request.send();

    logger.info("This request was sent: " + request.getBodyContents());
    logger.info("This response was received: " + response.getBody());
    listener.getLogger().println("Sending build status " + buildStatus.getState() + " for commit "
            + buildStatusResource.getCommitId() + " to BitBucket is done!");
}

From source file:org.lastaflute.core.json.SimpleJsonManager.java

License:Apache License

protected void setupPrettyPrintingSettings(GsonBuilder builder, boolean prettyPrinting) {
    if (prettyPrinting) {
        builder.setPrettyPrinting();
    }/*from w ww .  j  a v  a 2  s .  co  m*/
}

From source file:org.megam.deccanplato.provider.box.handler.FileImpl.java

License:Open Source License

/**
 * @return//from   www  .j  av a  2  s.  c  o m
 */
private Map<String, String> share() {

    Map<String, String> outMap = new HashMap<>();
    final String BOX_UPLOAD = "/files/" + args.get(FILE_ID);

    Map<String, String> headerMap = new HashMap<String, String>();
    headerMap.put("Authorization", "BoxAuth api_key=" + args.get(API_KEY) + "&auth_token=" + args.get(TOKEN));

    Map<String, String> access = new HashMap<>();
    access.put("access", "open");
    access.put("unshared_at", "2013-02-28T12:07:46.981+05:30");
    Map<String, String> pAccess = new HashMap<>();
    pAccess.put("can_download ", "Company");
    pAccess.put(" can_preview ", "Company");
    Map<String, Map<String, String>> links = new HashMap<>();
    links.put("shared_link", access);
    links.put("permissions", pAccess);

    TransportTools tools = new TransportTools(BOX_URI + BOX_UPLOAD, null, headerMap);
    GsonBuilder gson = new GsonBuilder();
    gson.registerTypeAdapter(DateTime.class, new DateTimeTypeConverter());
    Gson obj = gson.setPrettyPrinting().create();
    System.out.println(obj.toJson(links));
    tools.setContentType(ContentType.APPLICATION_JSON, obj.toJson(links));
    String responseBody = "";
    TransportResponse response = null;
    try {
        response = TransportMachinery.put(tools);
        responseBody = response.entityToString();
        System.out.println("OUTPUT:" + responseBody);
    } catch (ClientProtocolException ce) {
        ce.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
    outMap.put(OUTPUT, responseBody);
    return outMap;
}