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:com.stratio.explorer.notebook.Note.java

License:Apache License

public static Note load(String id, ExplorerConfiguration conf, NoteInterpreterLoader replLoader,
        Scheduler scheduler, JobListenerFactory jobListenerFactory, org.quartz.Scheduler quartzSched)
        throws IOException {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setPrettyPrinting();
    Gson gson = gsonBuilder.create();//w  ww  .  j av a 2 s. c o  m
    Note note = null;

    File file = new File(conf.getExplorerDir() + "/" + id + "/note.json");
    logger.info("Load note {} from {}", id, file.getAbsolutePath());

    if (file.isFile()) {
        FileInputStream ins = new FileInputStream(file);
        String json = IOUtils.toString(ins, conf.getString(ConfVars.EXPLORER_ENCODING));
        note = gson.fromJson(json, Note.class);
        note.setExplorerConfiguration(conf);
        note.setReplLoader(replLoader);
        note.jobListenerFactory = jobListenerFactory;
        for (Paragraph p : note.paragraphs) {
            if (p.getStatus() == Job.Status.PENDING || p.getStatus() == Job.Status.REFRESH_RESULT
                    || p.getStatus() == Job.Status.RUNNING) {
                p.setStatus(Job.Status.ABORT);
            }
        }
    }

    return note;
}

From source file:com.sudoplay.joise.converter.JoiseJSONConverter.java

License:Apache License

public JoiseJSONConverter(boolean prettyPrint) {
    GsonBuilder builder = new GsonBuilder();
    if (prettyPrint) {
        builder.setPrettyPrinting();
    }/*from   ww  w. j  a  va  2s.c  o  m*/
    gson = builder.create();
}

From source file:com.teotigraphix.caustk.service.JsonUtils.java

License:Apache License

static String toGson(Object serialized, boolean prettyPrint) {
    GsonBuilder builder = new GsonBuilder();
    if (prettyPrint) {
        builder.setPrettyPrinting();
    }//from   ww w . j av  a  2  s  .  c om
    Gson gson = builder.create();
    if (serialized instanceof ISerialize)
        ((ISerialize) serialized).sleep();
    return gson.toJson(serialized);
}

From source file:com.termmed.utils.FixRels.java

License:Apache License

/**
 * Gets the params./*w  w w .j  a  v  a  2s .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("com.termmed.configuration.Parameters")));

}

From source file:com.theapocalypsemc.funcore.json.GsonFactory.java

License:Open Source License

/**
 * Creates a new instance of Gson for use anywhere
 * <p>//from w  w  w.  j av  a2 s .  co  m
 * Use @GsonIgnore in order to skip serialization and deserialization
 * </p>
 *
 * @return a Gson instance
 */
public static Gson getNewGson(boolean prettyPrinting) {
    GsonBuilder builder = new GsonBuilder().addSerializationExclusionStrategy(new ExposeExlusion())
            .addDeserializationExclusionStrategy(new ExposeExlusion())
            .registerTypeHierarchyAdapter(ItemStack.class, new NewItemStackAdapter()).disableHtmlEscaping();
    if (prettyPrinting)
        builder.setPrettyPrinting();
    return builder.create();
}

From source file:com.tsc9526.monalisa.tools.datatable.DataMap.java

License:Open Source License

public String toJson(boolean pretty) {
    GsonBuilder gb = MelpJson.createGsonBuilder();

    if (pretty) {
        gb.setPrettyPrinting();
    }/*from   www .j av a 2  s  . c o m*/

    return gb.create().toJson(this);
}

From source file:com.udeyrishi.androidelasticsearchdatamanager.JsonFormatter.java

License:Apache License

/**
 * Gets the {@link Gson} object configured with the settings of this {@link JsonFormatter}.
 *
 * @return The properly configured {@link Gson}.
 *//*from   w w  w.j a v  a  2 s  .  co m*/
public Gson getGson() {
    GsonBuilder gsonBuilder = new GsonBuilder();

    if (getUsePrettyJson()) {
        gsonBuilder.setPrettyPrinting();
    }

    if (getUseExplicitExposeAnnotation()) {
        gsonBuilder.excludeFieldsWithoutExposeAnnotation();
    }

    // Register custom serializers
    for (Map.Entry<Class<?>, JsonSerializer<?>> entry : serializers.entrySet()) {
        gsonBuilder.registerTypeHierarchyAdapter(entry.getKey(), entry.getValue());
    }

    for (Map.Entry<Class<?>, JsonDeserializer<?>> entry : deserializers.entrySet()) {
        gsonBuilder.registerTypeHierarchyAdapter(entry.getKey(), entry.getValue());
    }

    return gsonBuilder.create();
}

From source file:com.vaadin.addon.charts.model.AbstractConfigurationObject.java

/**
 * Returns default GSON builder for configuration serializer.
 *///from  w  ww .j av a 2  s. c o  m
public static GsonBuilder createGsonBuilder() {
    GsonBuilder builder = new GsonBuilder();
    // uncomment if you wish to debug generated json
    builder.setPrettyPrinting();
    builder.registerTypeHierarchyAdapter(ChartEnum.class, new ChartEnumSerializer());
    builder.registerTypeHierarchyAdapter(SolidColor.class, new SolidColorSerializer());
    builder.registerTypeHierarchyAdapter(AxisList.class, new AxisListSerializer());
    builder.registerTypeHierarchyAdapter(PaneList.class, new PaneListSerializer());
    builder.registerTypeAdapter(ContainerDataSeries.class, new ContainerDataSeriesSerializer());
    builder.registerTypeAdapterFactory(new DataSeriesItemTypeAdapterFactory());
    builder.registerTypeAdapterFactory(new AbstractSeriesTypeAdapterFactory());
    builder.registerTypeAdapterFactory(new TitleTypeAdapterFactory());
    return builder;
}

From source file:com.vmware.dcp.common.serialization.JsonMapper.java

License:Open Source License

public static GsonBuilder createDefaultGsonBuilder(boolean isCompact) {
    GsonBuilder bldr = new GsonBuilder();

    registerCommonGsonTypeAdapters(bldr);

    if (isCompact) {
        bldr.disableHtmlEscaping();// w  ww.  j av  a  2  s .co  m
    } else {
        bldr.setPrettyPrinting();
    }

    return bldr;
}

From source file:com.vmware.xenon.common.serialization.JsonMapper.java

License:Open Source License

public static GsonBuilder createDefaultGsonBuilder(boolean isCompact, boolean isSensitive) {
    GsonBuilder bldr = new GsonBuilder();

    registerCommonGsonTypeAdapters(bldr);

    if (!isCompact) {
        bldr.setPrettyPrinting();
    }/* www.  jav  a  2s  .  co m*/

    bldr.disableHtmlEscaping();

    if (isSensitive) {
        bldr.addSerializationExclusionStrategy(new SensitiveAnnotationExclusionStrategy());
    }

    return bldr;
}