类com.google.gson.LongSerializationPolicy源码实例Demo

下面列出了怎么用com.google.gson.LongSerializationPolicy的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: packagedrone   文件: ChannelModelProvider.java
static Gson createGson ()
{
    final GsonBuilder builder = new GsonBuilder ();

    builder.setPrettyPrinting ();
    builder.setLongSerializationPolicy ( LongSerializationPolicy.STRING );
    builder.setDateFormat ( DATE_FORMAT );
    builder.registerTypeAdapter ( MetaKey.class, new JsonDeserializer<MetaKey> () {

        @Override
        public MetaKey deserialize ( final JsonElement json, final Type type, final JsonDeserializationContext ctx ) throws JsonParseException
        {
            return MetaKey.fromString ( json.getAsString () );
        }
    } );

    return builder.create ();
}
 
源代码2 项目: reactor-guice   文件: GsonHttpMessageConverter.java
public GsonHttpMessageConverter() {
    this.gson = new GsonBuilder()
        .serializeNulls()
        .setDateFormat("yyyy-MM-dd HH:mm:ss")
        .setLongSerializationPolicy(LongSerializationPolicy.STRING)
        .create();
}
 
源代码3 项目: reactor-guice   文件: Module.java
@Singleton
@Provides
public Gson gson () {
    return new GsonBuilder()
        .serializeNulls()
        .setDateFormat("yyyy-MM-dd HH:mm:ss")
        .setLongSerializationPolicy(LongSerializationPolicy.STRING)
        .create();
}
 
public MyGsonHttpMessageConverter() {
    this.gson = new GsonBuilder()
        .serializeNulls()
        .setDateFormat("yyyy-MM-dd HH:mm:ss")
        .setLongSerializationPolicy(LongSerializationPolicy.STRING)
        // .excludeFieldsWithoutExposeAnnotation()
        .create();
}
 
源代码5 项目: qmq   文件: DefaultMessageStore.java
DefaultMessageStore(DataSource datasource, RouterSelector routerSelector, SqlStatementProvider sqlStatementProvider) {
    this.sqlStatementProvider = sqlStatementProvider;
    this.platform = new JdbcTemplate(datasource);
    this.insertStatementFactory = createFactory();
    this.gson = new GsonBuilder().setLongSerializationPolicy(LongSerializationPolicy.STRING).create();
    this.routerSelector = routerSelector;
}
 
源代码6 项目: PHONK   文件: GSONUtil.java
GSONUtil() {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.setLongSerializationPolicy(LongSerializationPolicy.STRING);
    // gsonBuilder.setPrettyPrinting();

    gson = gsonBuilder.create();
}
 
源代码7 项目: exonum-java-binding   文件: JsonSerializer.java
/**
 * Returns preconfigured {@link Gson} builder instance. Can be useful in cases when
 * some customization is required. For example, type adapters should be extended or replaced.
 */
public static GsonBuilder builder() {
  return new GsonBuilder()
      .registerTypeHierarchyAdapter(TransactionMessage.class,
          new TransactionMessageJsonSerializer())
      .registerTypeHierarchyAdapter(HashCode.class, new HashCodeJsonSerializer())
      .registerTypeAdapter(PublicKey.class, new PublicKeyJsonSerializer())
      .registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeJsonSerializer())
      .registerTypeAdapterFactory(CommonTypeAdapterFactory.create())
      .setLongSerializationPolicy(LongSerializationPolicy.STRING);
}
 
源代码8 项目: sumk   文件: HttpGson.java
private static GsonBuilder gsonBuilder() {
	GsonBuilder gb = GsonHelper.builder("sumk.http");

	if (AppInfo.getBoolean("sumk.http.json.long2String", true)) {
		gb.setLongSerializationPolicy(LongSerializationPolicy.STRING);
	}
	return gb;
}
 
源代码9 项目: gson   文件: PrimitiveTest.java
public void testLongAsStringSerialization() throws Exception {
  gson = new GsonBuilder().setLongSerializationPolicy(LongSerializationPolicy.STRING).create();
  String result = gson.toJson(15L);
  assertEquals("\"15\"", result);

  // Test with an integer and ensure its still a number
  result = gson.toJson(2);
  assertEquals("2", result);
}
 
源代码10 项目: gson   文件: PrimitiveTest.java
public void testLongAsStringDeserialization() throws Exception {
  long value = gson.fromJson("\"15\"", long.class);
  assertEquals(15, value);

  gson = new GsonBuilder().setLongSerializationPolicy(LongSerializationPolicy.STRING).create();
  value = gson.fromJson("\"25\"", long.class);
  assertEquals(25, value);
}
 
源代码11 项目: gson   文件: JavaUtilConcurrentAtomicTest.java
public void testAtomicLongWithStringSerializationPolicy() throws Exception {
  Gson gson = new GsonBuilder()
      .setLongSerializationPolicy(LongSerializationPolicy.STRING)
      .create();
  AtomicLongHolder target = gson.fromJson("{'value':'10'}", AtomicLongHolder.class);
  assertEquals(10, target.value.get());
  String json = gson.toJson(target);
  assertEquals("{\"value\":\"10\"}", json);
}
 
源代码12 项目: gson   文件: JavaUtilConcurrentAtomicTest.java
public void testAtomicLongArrayWithStringSerializationPolicy() throws Exception {
  Gson gson = new GsonBuilder()
      .setLongSerializationPolicy(LongSerializationPolicy.STRING)
      .create();
  AtomicLongArray target = gson.fromJson("['10', '13', '14']", AtomicLongArray.class);
  assertEquals(3, target.length());
  assertEquals(10, target.get(0));
  assertEquals(13, target.get(1));
  assertEquals(14, target.get(2));
  String json = gson.toJson(target);
  assertEquals("[\"10\",\"13\",\"14\"]", json);
}
 
源代码13 项目: sumk   文件: GsonHelper.java
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;
}
 
 类所在包
 同包方法