Java Code Examples for com.google.gson.GsonBuilder#disableHtmlEscaping()

The following examples show how to use com.google.gson.GsonBuilder#disableHtmlEscaping() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResolveSaiy.java    From Saiy-PS with GNU Affero General Public License v3.0 6 votes vote down vote up
public void unpack(@NonNull final JSONObject payload) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "unpacking");
    }

    final GsonBuilder builder = new GsonBuilder();
    builder.disableHtmlEscaping();
    builder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);

    final Gson gson = builder.create();
    nluSaiy = gson.fromJson(payload.toString(), new TypeToken<NLUSaiy>() {
    }.getType());

    new NLUCoerce(getNLUSaiy(), getContext(), getSupportedLanguage(), getVRLocale(), getTTSLocale(),
            getConfidenceArray(), getResultsArray()).coerce();
}
 
Example 2
Source File: JsonUtils.java    From kurento-java with Apache License 2.0 6 votes vote down vote up
/**
 * Gson object accessor (getter).
 *
 * @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;
}
 
Example 3
Source File: DagBuilder.java    From karamel with Apache License 2.0 6 votes vote down vote up
private static RunRecipeTask makeRecipeTaskIfNotExist(String recipeName, MachineRuntime machine,
    ClusterStats clusterStats, JsonObject chefJson,
    TaskSubmitter submitter, String cookbookId, String cookbookName, Map<String, RunRecipeTask> allRecipeTasks,
    Dag dag, List<KaramelizedCookbook> rootCookbooks) throws DagConstructionException {
  String recId = RunRecipeTask.makeUniqueId(machine.getId(), recipeName);
  RunRecipeTask runRecipeTask = allRecipeTasks.get(recId);
  if (!allRecipeTasks.containsKey(recId)) {
    ChefJsonGenerator.addRunListForRecipe(chefJson, recipeName);
    GsonBuilder builder = new GsonBuilder();
    builder.disableHtmlEscaping();
    Gson gson = builder.setPrettyPrinting().create();
    String jsonString = gson.toJson(chefJson);
    runRecipeTask
        = new RunRecipeTask(machine, clusterStats, recipeName, jsonString,
            submitter, cookbookId, cookbookName, rootCookbooks);
    dag.addTask(runRecipeTask);
  }
  allRecipeTasks.put(recId, runRecipeTask);
  return runRecipeTask;
}
 
Example 4
Source File: GsonFactoryBean.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public void afterPropertiesSet() {
	GsonBuilder builder = (this.base64EncodeByteArrays ?
			GsonBuilderUtils.gsonBuilderWithBase64EncodedByteArrays() : new GsonBuilder());
	if (this.serializeNulls) {
		builder.serializeNulls();
	}
	if (this.prettyPrinting) {
		builder.setPrettyPrinting();
	}
	if (this.disableHtmlEscaping) {
		builder.disableHtmlEscaping();
	}
	if (this.dateFormatPattern != null) {
		builder.setDateFormat(this.dateFormatPattern);
	}
	this.gson = builder.create();
}
 
Example 5
Source File: GsonFactoryBean.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public void afterPropertiesSet() {
	GsonBuilder builder = (this.base64EncodeByteArrays ?
			GsonBuilderUtils.gsonBuilderWithBase64EncodedByteArrays() : new GsonBuilder());
	if (this.serializeNulls) {
		builder.serializeNulls();
	}
	if (this.prettyPrinting) {
		builder.setPrettyPrinting();
	}
	if (this.disableHtmlEscaping) {
		builder.disableHtmlEscaping();
	}
	if (this.dateFormatPattern != null) {
		builder.setDateFormat(this.dateFormatPattern);
	}
	this.gson = builder.create();
}
 
Example 6
Source File: ResolveNuance.java    From Saiy-PS with GNU Affero General Public License v3.0 6 votes vote down vote up
public void unpack(@NonNull final JSONObject payload) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "unpacking");
    }

    final GsonBuilder builder = new GsonBuilder();
    builder.disableHtmlEscaping();
    builder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);

    final Gson gson = builder.create();
    nluNuance = gson.fromJson(payload.toString(), new TypeToken<NLUNuance>() {
    }.getType());

    new NLUCoerce(getNLUNuance(), getContext(), getSupportedLanguage(), getVRLocale(), getTTSLocale(),
            getConfidenceArray(), getResultsArray()).coerce();
}
 
Example 7
Source File: GsonFactoryBean.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void afterPropertiesSet() {
	GsonBuilder builder = (this.base64EncodeByteArrays ?
			GsonBuilderUtils.gsonBuilderWithBase64EncodedByteArrays() : new GsonBuilder());
	if (this.serializeNulls) {
		builder.serializeNulls();
	}
	if (this.prettyPrinting) {
		builder.setPrettyPrinting();
	}
	if (this.disableHtmlEscaping) {
		builder.disableHtmlEscaping();
	}
	if (this.dateFormatPattern != null) {
		builder.setDateFormat(this.dateFormatPattern);
	}
	this.gson = builder.create();
}
 
Example 8
Source File: GsonFactoryBean.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public void afterPropertiesSet() {
	GsonBuilder builder = (this.base64EncodeByteArrays ?
			GsonBuilderUtils.gsonBuilderWithBase64EncodedByteArrays() : new GsonBuilder());
	if (this.serializeNulls) {
		builder.serializeNulls();
	}
	if (this.prettyPrinting) {
		builder.setPrettyPrinting();
	}
	if (this.disableHtmlEscaping) {
		builder.disableHtmlEscaping();
	}
	if (this.dateFormatPattern != null) {
		builder.setDateFormat(this.dateFormatPattern);
	}
	this.gson = builder.create();
}
 
Example 9
Source File: CommonModel.java    From NoraUi with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public String serialize() {
    final GsonBuilder builder = new GsonBuilder();
    builder.excludeFieldsWithoutExposeAnnotation();
    builder.disableHtmlEscaping();
    final Gson gson = builder.create();
    return gson.toJson(this);
}
 
Example 10
Source File: AbstractWeixinmpController.java    From weixinmp4java with Apache License 2.0 5 votes vote down vote up
/**
 * 返回每个线程的gson解析器
 * @return
 */
private Gson getGson() {
    long id = Thread.currentThread().getId();
    Gson gson = gsonCache.get(id);
    if (gson == null) {
        GsonBuilder g = new GsonBuilder();
        g = g.disableHtmlEscaping(); // 禁用HTML转义
        gson = g.create();
        gsonCache.put(id, gson);
    }
    return gson;
}
 
Example 11
Source File: IotJobsClient.java    From aws-iot-device-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private Gson getGson() {
    GsonBuilder gson = new GsonBuilder();
    gson.disableHtmlEscaping();
    gson.registerTypeAdapter(Timestamp.class, new Timestamp.Serializer());
    gson.registerTypeAdapter(Timestamp.class, new Timestamp.Deserializer());
    addTypeAdapters(gson);
    return gson.create();
}
 
Example 12
Source File: IotShadowClient.java    From aws-iot-device-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private Gson getGson() {
    GsonBuilder gson = new GsonBuilder();
    gson.disableHtmlEscaping();
    gson.registerTypeAdapter(Timestamp.class, new Timestamp.Serializer());
    gson.registerTypeAdapter(Timestamp.class, new Timestamp.Deserializer());
    addTypeAdapters(gson);
    return gson.create();
}
 
Example 13
Source File: IotIdentityClient.java    From aws-iot-device-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private Gson getGson() {
    GsonBuilder gson = new GsonBuilder();
    gson.disableHtmlEscaping();
    gson.registerTypeAdapter(Timestamp.class, new Timestamp.Serializer());
    gson.registerTypeAdapter(Timestamp.class, new Timestamp.Deserializer());
    addTypeAdapters(gson);
    return gson.create();
}
 
Example 14
Source File: JsonLdSerializer.java    From schemaorg-java with Apache License 2.0 5 votes vote down vote up
public JsonLdSerializer(boolean setPrettyPrinting, boolean disableHtmlEscaping) {
  GsonBuilder gsonBuilder =
      new GsonBuilder()
          .registerTypeAdapter(thingTypeToken, new JsonLdTypeAdapter())
          .serializeNulls();
  if (setPrettyPrinting) {
    gsonBuilder.setPrettyPrinting();
  }
  if (disableHtmlEscaping) {
    gsonBuilder.disableHtmlEscaping();
  }
  gson = gsonBuilder.create();
}
 
Example 15
Source File: AzureParameterPane.java    From Microsoft-Cloud-Services-for-Android with MIT License 5 votes vote down vote up
private void updateDocument() {
    if ((mobileServicesCheckBox.isSelected()
            && !notificationHubCheckBox.isSelected()
            && selectedMobileService != null)
            || (!mobileServicesCheckBox.isSelected()
            && notificationHubCheckBox.isSelected()
            && senderID != null
            && connectionString != null
            && hubName != null)
            || (mobileServicesCheckBox.isSelected()
            && notificationHubCheckBox.isSelected()
            && selectedMobileService != null
            && senderID != null
            && connectionString != null
            && hubName != null)) {

        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.disableHtmlEscaping();
        Gson gson = gsonBuilder.create();

        AzureParameters azureParameters = new AzureParameters(
                mobileServicesCheckBox.isSelected(),
                notificationHubCheckBox.isSelected(),
                mobileServicesCheckBox.isSelected() ? selectedMobileService.getAppUrl() : null,
                mobileServicesCheckBox.isSelected() ? selectedMobileService.getAppKey() : null,
                notificationHubCheckBox.isSelected() ? senderID : null,
                notificationHubCheckBox.isSelected() ? connectionString : null,
                notificationHubCheckBox.isSelected() ? hubName : null);

        String stringVal = gson.toJson(azureParameters);

        setValue(stringVal);
    } else {
        setValue("");
    }
}
 
Example 16
Source File: ExtDirectGsonBuilderConfigurator.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void configure(final GsonBuilder builder, final GlobalConfiguration configuration) {
  if (configuration.getDebug()) {
    builder.setPrettyPrinting();
  }
  builder.serializeNulls();
  builder.disableHtmlEscaping();

  builder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
}
 
Example 17
Source File: JsonFunctions.java    From jphp with Apache License 2.0 5 votes vote down vote up
@Immutable
public static String json_encode(Memory memory, int options) {
    GsonBuilder builder;
    if (options != 0) {
        MemorySerializer serializer = new MemorySerializer();
        builder = JsonExtension.createGsonBuilder(serializer);

        if ((options & JsonConstants.JSON_PRETTY_PRINT) == JsonConstants.JSON_PRETTY_PRINT) {
            builder.setPrettyPrinting();
        }

        if ((options & JsonConstants.JSON_HEX_TAG) != JsonConstants.JSON_HEX_TAG) {
            builder.disableHtmlEscaping();
        }

        if ((options & JsonConstants.JSON_FORCE_OBJECT) == JsonConstants.JSON_FORCE_OBJECT) {
            serializer.setForceObject(true);
        }

        if ((options & JsonConstants.JSON_NUMERIC_CHECK) == JsonConstants.JSON_NUMERIC_CHECK) {
            serializer.setNumericCheck(true);
        }

        if ((options & JsonConstants.JSON_UNESCAPED_UNICODE) == JsonConstants.JSON_UNESCAPED_UNICODE) {
            serializer.unescapedUnicode(true);
        }
    } else {
        builder = JsonExtension.DEFAULT_GSON_BUILDER;
    }

    Gson gson = builder.create();
    return gson.toJson(memory);
}
 
Example 18
Source File: KaramelizedCookbook.java    From karamel with Apache License 2.0 5 votes vote down vote up
public String getInfoJson() {
  if (json == null) {
    CookbookInfoJson cookbookInfoJson = new CookbookInfoJson(urls.id, metadataRb);
    GsonBuilder builder = new GsonBuilder();
    builder.disableHtmlEscaping();
    Gson gson = builder.setPrettyPrinting().create();
    json = gson.toJson(cookbookInfoJson);
  }
  return json;
}
 
Example 19
Source File: GsonHelper.java    From sumk with Apache License 2.0 4 votes vote down vote up
public static GsonBuilder builder(String module) {
	if (module == null || module.isEmpty()) {
		module = "sumk";
	}

	DateTimeTypeAdapter da = new DateTimeTypeAdapter();
	String format = AppInfo.get(module + ".gson.date.format");
	if (StringUtil.isNotEmpty(format)) {
		da.setDateFormat(format);
	}

	GsonBuilder gb = new GsonBuilder().registerTypeAdapter(Date.class, da);

	if (AppInfo.getBoolean(module + ".gson.disableHtmlEscaping", false)) {
		gb.disableHtmlEscaping();
	}
	if (AppInfo.getBoolean(module + ".gson.shownull", false)) {
		gb.serializeNulls();
	}
	if (AppInfo.getBoolean(module + ".gson.disableInnerClassSerialization", false)) {
		gb.disableInnerClassSerialization();
	}
	if (AppInfo.getBoolean(module + ".gson.generateNonExecutableJson", false)) {
		gb.generateNonExecutableJson();
	}
	if (AppInfo.getBoolean(module + ".gson.serializeSpecialFloatingPointValues", false)) {
		gb.serializeSpecialFloatingPointValues();
	}

	if (AppInfo.getBoolean(module + ".gson.longSerialize2String", false)) {
		gb.setLongSerializationPolicy(LongSerializationPolicy.STRING);
	}

	if (AppInfo.getBoolean(module + ".gson.prettyPrinting", false)) {
		gb.setPrettyPrinting();
	}
	if (AppInfo.getBoolean(module + ".gson.date.adaper", true)) {
		DateAdapters.registerAll(gb);
	}
	return gb;
}
 
Example 20
Source File: GsonFactory.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
private static Gson create(
      Set<TypeAdapterFactory> typeAdapterFactories,
      Set<TypeAdapter<?>> typeAdapters,
      Set<JsonSerializer<?>> serializers,
      Set<JsonDeserializer<?>> deserializers,
      boolean serializeNulls
) {
   IrisObjectTypeAdapterFactory.install();

   GsonBuilder builder = new GsonBuilder();
   if (serializeNulls) {
      builder.serializeNulls();
   }

   builder.disableHtmlEscaping();
   builder.registerTypeAdapter(Date.class, new DateTypeAdapter());

   if(typeAdapterFactories != null) {
      for(TypeAdapterFactory factory : typeAdapterFactories) {
         builder.registerTypeAdapterFactory(factory);
      }
   }

   if(typeAdapters != null) {
      for(TypeAdapter<?> adapter : typeAdapters) {
         builder.registerTypeAdapter(extractType(adapter), adapter);
      }
   }

   if(serializers != null) {
      for(JsonSerializer<?> serializer : serializers) {
         builder.registerTypeAdapter(extractType(serializer, JsonSerializer.class), serializer);
      }
   }

   if(deserializers != null) {
      for(JsonDeserializer<?> deserializer : deserializers) {
         builder.registerTypeAdapter(extractType(deserializer, JsonDeserializer.class), deserializer);
      }
   }

   return builder.create();
}