Example usage for com.google.gson GsonBuilder disableHtmlEscaping

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

Introduction

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

Prototype

public GsonBuilder disableHtmlEscaping() 

Source Link

Document

By default, Gson escapes HTML characters such as < > etc.

Usage

From source file:org.bob.web.applications.smlite.rest.config.GSONMessageBodyHandler.java

License:Open Source License

private Gson getGson() {
    //System.out.println("******************************** getGson **********************");
    if (gson == null) {
        final GsonBuilder gsonBuilder = new GsonBuilder();
        gson = gsonBuilder.disableHtmlEscaping()
                //.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CAMEL_CASE)
                .setPrettyPrinting().serializeNulls()
                //.setDateFormat("dd/MM/yyyy HH:mm:SS.s")
                .setDateFormat("yyyy-MM-dd HH:mm:ss.SSS").create();
    }//from w w  w .  ja v a2 s  .c o m
    return gson;
}

From source file:org.chililog.server.common.JsonTranslator.java

License:Apache License

/**
 * <p>//from w  ww  .j av  a  2s .  c o  m
 * Singleton constructor that creates our reusable GSON object.
 * </p>
 * 
 * <p>
 * If there are any errors, the JVM is terminated. Without valid application properties, we will fall over elsewhere
 * so might as well terminate here.
 * </p>
 */
private JsonTranslator() {
    try {
        GsonBuilder builder = new GsonBuilder();
        if (AppProperties.getInstance().getJsonPretty()) {
            builder.setPrettyPrinting();
        }
        builder.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        builder.setFieldNamingStrategy(new ChiliLogFieldNamingStrategy());
        builder.disableHtmlEscaping();
        _gson = builder.create();
    } catch (Exception e) {
        _logger.error("Error initializing JSON translator: " + e.getMessage(), e);
        System.exit(1);
    }
}

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 ww w  .  jav  a2 s. co 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.kurento.jsonrpc.JsonUtils.java

License:Apache License

/**
 * Gson object accessor (getter)./*from w w  w.j  a va  2 s.c  om*/
 *
 * @return son object
 */
public static Gson getGson() {

    if (gson == null) {
        synchronized (JsonUtils.class) {
            if (gson == null) {
                GsonBuilder builder = new GsonBuilder();
                builder.registerTypeAdapter(Request.class, new JsonRpcRequestDeserializer());

                builder.registerTypeAdapter(Response.class, new JsonRpcResponseDeserializer());

                builder.registerTypeAdapter(Props.class, new JsonPropsAdapter());

                builder.disableHtmlEscaping();

                gson = builder.create();
            }
        }
    }

    return gson;
}

From source file:org.kurento.modulecreator.json.JsonModuleSaverLoader.java

License:Apache License

private JsonModuleSaverLoader() {
    GsonBuilder gsonBuilder = new GsonBuilder().setPrettyPrinting();
    gsonBuilder.registerTypeAdapter(TypeRef.class, new TypeRefAdapter());
    gsonBuilder.registerTypeAdapter(Param.class, new DataItemAdapter());
    gsonBuilder.registerTypeAdapter(Property.class, new DataItemAdapter());
    gsonBuilder.registerTypeAdapter(RemoteClass.class, new RemoteClassAdapter());
    gsonBuilder.registerTypeAdapter(Method.class, new MethodAdapter());
    gsonBuilder.disableHtmlEscaping();
    gson = gsonBuilder.create();/*from   w  ww . j  a  va  2  s .  c  o  m*/
}

From source file:org.ldaptive.io.JsonReader.java

License:Open Source License

/**
 * Creates a new json reader.//from w ww.  jav  a 2s. c o m
 *
 * @param  reader  to read JSON from
 * @param  sb  sort behavior of the search result
 */
public JsonReader(final Reader reader, final SortBehavior sb) {
    jsonReader = reader;
    if (sb == null) {
        throw new IllegalArgumentException("Sort behavior cannot be null");
    }
    final GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(SearchResult.class, new SearchResultDeserializer(sb));
    gson = builder.disableHtmlEscaping().create();
}

From source file:org.ldaptive.io.JsonWriter.java

License:Open Source License

/**
 * Creates a new json writer.//from   www  . ja va 2  s. c  o m
 *
 * @param  writer  to write JSON to
 */
public JsonWriter(final Writer writer) {
    jsonWriter = writer;
    final GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(SearchResult.class, new SearchResultSerializer());
    gson = builder.disableHtmlEscaping().create();
}

From source file:org.restcomm.connect.http.UsageEndpoint.java

License:Open Source License

@PostConstruct
public void init() {
    final DaoManager storage = (DaoManager) context.getAttribute(DaoManager.class.getName());
    configuration = (Configuration) context.getAttribute(Configuration.class.getName());
    configuration = configuration.subset("runtime-settings");
    super.init(configuration);
    dao = storage.getUsageDao();//  www.java  2s  .  c  o  m
    final UsageConverter converter = new UsageConverter(configuration);
    final GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Usage.class, converter);
    builder.setPrettyPrinting();
    gson = builder.disableHtmlEscaping().create();
    xstream = new XStream();
    xstream.alias("RestcommResponse", RestCommResponse.class);
    xstream.registerConverter(converter);
    xstream.registerConverter(new UsageListConverter(configuration));
    xstream.registerConverter(new RestCommResponseConverter(configuration));
}

From source file:org.sensorhub.impl.module.ModuleConfigJsonFile.java

License:Mozilla Public License

public ModuleConfigJsonFile(String moduleConfigPath) {
    configFile = new File(moduleConfigPath);
    configMap = new LinkedHashMap<String, ModuleConfig>();

    // init json serializer/deserializer
    final GsonBuilder builder = new GsonBuilder();
    builder.setPrettyPrinting();/* w  ww  .  j av a 2 s .co  m*/
    builder.disableHtmlEscaping();
    builder.registerTypeAdapterFactory(new RuntimeTypeAdapterFactory<Object>(Object.class, OBJ_CLASS_FIELD));

    gson = builder.create();
    readJSON();
}

From source file:org.sonatype.nexus.extdirect.internal.ExtDirectGsonBuilderConfigurator.java

License:Open Source License

@Override
public void configure(final GsonBuilder builder, final GlobalConfiguration configuration) {
    if (configuration.getDebug()) {
        builder.setPrettyPrinting();/* w  ww  .j a  v a 2 s .  co m*/
    }
    builder.serializeNulls();
    builder.disableHtmlEscaping();

    builder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
}