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:edu.isi.wings.portal.classes.JsonHandler.java

License:Apache License

public static Gson createComponentJson() {
    GsonBuilder gson = new GsonBuilder();
    gson.setDateFormat("yyyy-MM-dd");
    return gson.disableHtmlEscaping().create();
    //return gson.disableHtmlEscaping().setPrettyPrinting().create();
}

From source file:edu.isi.wings.portal.classes.JsonHandler.java

License:Apache License

public static Gson createTemplateGson() {
    GsonBuilder gson = new GsonBuilder();
    gson.registerTypeAdapter(Link.class, new LinkSerializer());
    //gson.registerTypeAdapter(Node.class, new NodeSerializer());
    gson.registerTypeAdapter(Binding.class, new BindingSerializer());
    gson.registerTypeAdapter(Binding.class, new BindingDeserializer());
    gson.registerTypeAdapter(ValueBinding.class, new BindingSerializer());
    gson.registerTypeAdapter(ValueBinding.class, new BindingDeserializer());
    gson.registerTypeAdapter(SetExpression.class, new SetExpressionSerializer());
    gson.registerTypeAdapter(SetExpression.class, new SetExpressionDeserializer());
    //gson.registerTypeAdapter(URI.class, new URISerializer());
    //gson.registerTypeAdapter(String.class, new StringSerializer());
    gson.setDateFormat("yyyy-MM-dd");
    gson.disableHtmlEscaping();
    //gson.setPrettyPrinting();
    return gson.create();
}

From source file:ee.ria.xroad.common.util.JsonUtils.java

License:Open Source License

/**
 * Get Gson with custom serializer.//from   w w  w .  j  a va2  s  .  c  o m
 * @return Gson instance with custom serializer.
 */
public static Gson getSerializer() {
    GsonBuilder builder = new GsonBuilder();
    builder.disableHtmlEscaping();
    builder.registerTypeAdapter(ClientId.class, new ClientIdSerializer());

    builder.setExclusionStrategies(new ExclusionStrategy() {
        @Override
        public boolean shouldSkipField(FieldAttributes f) {
            return f.getAnnotation(Exclude.class) != null;
        }

        @Override
        public boolean shouldSkipClass(Class<?> clazz) {
            return false;
        }
    });

    return builder.create();
}

From source file:elaborate.tag_analysis.oosm.impl.gson.GsonFactory.java

public static Gson createGson() {
    GsonBuilder builder = new GsonBuilder();
    //builder.registerTypeAdapter(OOSMElement.class, new OOSMElementInstanceCreator());
    //builder.registerTypeAdapter(OOSMRule.class, new OOSMRuleInstanceCreator());
    /*builder.registerTypeAdapter(OOSMRule.class, new InterfaceDeserializer<OOSMRule>(new OOSMRuleInstanceCreator()));
    builder.registerTypeAdapter(OOSMElement.class, new InterfaceDeserializer<OOSMElement>(new OOSMElementInstanceCreator()));
    builder.registerTypeAdapter(OOSMElementList.class, new InterfaceDeserializer<OOSMElementList>(new OOSMElementListInstanceCreator()));*/

    builder.registerTypeAdapter(OOSMRule.class, new OOSMRuleInterfaceDeserializer());
    builder.registerTypeAdapter(OOSMElement.class, new OOSMElementInterfaceDeserializer());
    builder.registerTypeAdapter(OOSMElementList.class, new OOSMElementListInterfaceDeserializer());
    builder.disableHtmlEscaping();

    return builder.create();
}

From source file:hd3gtv.mydmam.db.BackupDbElasticsearch.java

License:Open Source License

BackupDbElasticsearch(File outfile, String index_name,
        ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mapping,
        ImmutableOpenMap<String, Settings> settings) throws Exception {
    quotedprintablecodec = new QuotedPrintableCodec("UTF-8");
    GsonBuilder g_builder = new GsonBuilder();
    g_builder.disableHtmlEscaping();
    if (BackupDb.mode_debug) {
        g_builder.setPrettyPrinting();/*w w  w  .j  av a2 s. co m*/
    }
    gson = g_builder.create();

    /**
     * Preparation
     */
    fileoutputstream = new FileOutputStream(outfile);

    OutputFormat of = new OutputFormat();
    of.setMethod("xml");
    of.setEncoding("UTF-8");
    of.setVersion("1.0");
    of.setIndenting(BackupDb.mode_debug);
    if (BackupDb.mode_debug) {
        of.setIndent(2);
    }

    serializer = new XMLSerializer(fileoutputstream, of);
    content = serializer.asContentHandler();
    content.startDocument();

    /**
     * Headers
     */
    AttributesImpl atts = new AttributesImpl();
    atts.addAttribute("", "", "name", "CDATA", index_name);
    atts.addAttribute("", "", "created", "CDATA", String.valueOf(System.currentTimeMillis()));
    if (BackupDb.mode_debug) {
        atts.addAttribute("", "", "created_date", "CDATA", (new Date()).toString());
    }
    content.startElement("", "", "index", atts);

    /**
     * Import configuration
     * ES Mapping
     */
    String jo_mapping;
    ImmutableOpenMap<String, MappingMetaData> mapping_value;
    for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> mapping_cursor : mapping) {
        mapping_value = mapping_cursor.value;
        for (ObjectObjectCursor<String, MappingMetaData> mapping_value_cursor : mapping_value) {
            atts.clear();
            atts.addAttribute("", "", "name", "CDATA", mapping_value_cursor.key);

            content.startElement("", "", "mapping", atts);

            jo_mapping = gson.toJson(mapping_value_cursor.value.getSourceAsMap());

            if (BackupDb.mode_debug) {
                serializer.comment(jo_mapping);
            }

            jo_mapping = new String(quotedprintablecodec.encode(jo_mapping));
            content.characters(jo_mapping.toCharArray(), 0, jo_mapping.length());

            content.endElement("", "", "mapping");
        }
    }

    /**
     * ES settings
     */
    for (ObjectObjectCursor<String, Settings> settings_cursor : settings) {
        atts.clear();
        content.startElement("", "", "settings", atts);

        jo_mapping = gson.toJson(settings_cursor.value.getAsMap());

        if (BackupDb.mode_debug) {
            serializer.comment(jo_mapping);
        }

        jo_mapping = new String(quotedprintablecodec.encode(jo_mapping));
        content.characters(jo_mapping.toCharArray(), 0, jo_mapping.length());

        content.endElement("", "", "settings");
    }
}

From source file:info.bonjean.beluga.util.GsonUtil.java

License:Open Source License

public static Gson getGsonInstance() {
    if (gson == null) {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.disableHtmlEscaping();
        gson = gsonBuilder.create();//w  w  w.  j  a v a 2  s  .c  o m
    }

    return gson;
}

From source file:mobi.jenkinsci.model.ItemNode.java

License:Apache License

private Gson getGson() {
    final GsonBuilder gbuilder = new GsonBuilder();
    gbuilder.disableHtmlEscaping();
    if (JSON_PRETTY_PRINTING) {
        gbuilder.setPrettyPrinting();//from  w w w .j av  a  2s . c  o  m
    }
    final Gson gson = gbuilder.create();
    return gson;
}

From source file:mobi.jenkinsci.model.ItemNode.java

License:Apache License

public InputStream toJsonStream() {

    final GsonBuilder gbuilder = new GsonBuilder();
    gbuilder.disableHtmlEscaping();

    final StringWriter writer = new StringWriter();
    gbuilder.create().toJson(this, writer);

    final InputStream result = new ByteArrayInputStream(writer.getBuffer().toString().getBytes());
    return result;
}

From source file:net.redstoneore.legacyfactions.Factions.java

License:Open Source License

public GsonBuilder getGsonBuilder() {
    if (this.gsonBuilder == null) {
        Type mapFLocToStringSetType = new TypeToken<Map<FLocation, Set<String>>>() {
        }.getType();/*from  www . java 2 s .c o  m*/
        Type mapLocalityToStringSetType = new TypeToken<Map<Locality, Set<String>>>() {
        }.getType();
        GsonBuilder builder = new GsonBuilder().setPrettyPrinting();

        try {
            builder.setLenient();
        } catch (NoSuchMethodError e) {
            // older minecraft plugins don't have this in their version of Gson
        }

        this.gsonBuilder = builder.disableHtmlEscaping()
                .excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE)
                .registerTypeAdapter(LazyLocation.class, new LazyLocationAdapter())
                .registerTypeAdapter(mapFLocToStringSetType, new MapFlocationSetAdapter())
                .registerTypeAdapter(mapLocalityToStringSetType, new MapLocalitySetAdapter())
                .registerTypeAdapter(CrossColour.class, new CrossColourAdapter())
                .registerTypeAdapter(CrossEntityType.class, new CrossEntityTypeAdapter())

        ;
    }

    return this.gsonBuilder;
}

From source file:org.bimserver.collada.OpenGLTransmissionFormatSerializer.java

License:Open Source License

private void jsonTheDirectory(OutputStream outputStream, File writeDirectory)
        throws UnsupportedEncodingException, IOException {
    // Create a root object.
    JsonObject root = new JsonObject();
    // Put the individual files into a JSON file.
    for (File f : writeDirectory.listFiles(ignoreDAEFilter))
        addFileToJSON(root, f);//  w  ww. ja v a2 s. co  m
    // Configure the builder.
    GsonBuilder builder = new GsonBuilder();
    builder.disableHtmlEscaping();
    if (wantJSONPrettyPrint)
        builder.setPrettyPrinting();
    Gson gson = builder.create();
    // Get the JSON string.
    String output = gson.toJson(root);
    // Push the data into the parent stream (gets returned to the server).
    outputStream.write(output.getBytes());
}