Java 类com.google.gson.LongSerializationPolicy 实例源码
项目:processor
文件:EventFactory.java
public Gson create() {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(Id.class, new IdSerializer());
gsonBuilder.registerTypeAdapter(Type.class, new TypeSerializer());
gsonBuilder.registerTypeAdapter(Visitor.class, new VisitorSerializer());
gsonBuilder.registerTypeAdapter(Session.class, new SessionSerializer());
gsonBuilder.registerTypeAdapter(Map.class, new MapSerializer());
gsonBuilder.registerTypeAdapter(Payload.class, new MapSerializer());
gsonBuilder.serializeNulls();
gsonBuilder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
gsonBuilder.setLongSerializationPolicy(LongSerializationPolicy.STRING);
gsonBuilder.enableComplexMapKeySerialization();
return gsonBuilder.create();
}
项目: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 ();
}
项目:package-drone
文件: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 ();
}
项目:phonk
文件:ProtoSingleton.java
ProtoSingleton() {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setLongSerializationPolicy(LongSerializationPolicy.STRING);
// gsonBuilder.setPrettyPrinting();
gson = gsonBuilder.create();
}
项目:oson
文件:PrimitiveTest.java
public void testLongAsStringDeserialization() throws Exception {
long value = oson.fromJson("\"15\"", long.class);
assertEquals(15, value);
gson = new GsonBuilder().setLongSerializationPolicy(LongSerializationPolicy.STRING).create();
value = oson.fromJson("\"25\"", long.class);
assertEquals(25, value);
}
项目:oson
文件:JavaUtilConcurrentAtomicTest.java
public void testAtomicLongWithStringSerializationPolicy() throws Exception {
Gson gson = new GsonBuilder()
.setLongSerializationPolicy(LongSerializationPolicy.STRING)
.create();
AtomicLongHolder target = oson.fromJson("{'value':'10'}", AtomicLongHolder.class);
assertEquals(10, target.value.get());
String json = oson.toJson(target);
assertEquals("{\"value\":10}", json);
}
项目:oson
文件:JavaUtilConcurrentAtomicTest.java
public void testAtomicLongArrayWithStringSerializationPolicy() throws Exception {
Gson gson = new GsonBuilder()
.setLongSerializationPolicy(LongSerializationPolicy.STRING)
.create();
AtomicLongArray target = oson.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 = oson.toJson(target);
assertEquals("[10,13,14]", json);
}
项目:StaticGson
文件:LongSerializationPolicyTest.java
@Before
public void setUp() throws Exception {
gson = new GsonBuilder()
.registerTypeAdapterFactory(StaticGsonTypeAdapterFactory.newInstance())
.setLongSerializationPolicy(LongSerializationPolicy.STRING)
.create();
}
项目:sumk
文件:HttpGson.java
private static GsonBuilder pcGsonBuilder() {
String module = "http.pc";
DateTimeTypeAdapter da = new DateTimeTypeAdapter();
String format = AppInfo.get(module + ".json.date.format", SumkDate.DATE_TIME_MILS);
if (StringUtil.isNotEmpty(format)) {
da.setDateFormat(format);
}
GsonBuilder gb = new GsonBuilder().registerTypeAdapter(Date.class, da);
if (AppInfo.getBoolean(module + ".json.disableHtmlEscaping", true)) {
gb.disableHtmlEscaping();
}
if (AppInfo.getBoolean(module + ".json.shownull", false)) {
gb.serializeNulls();
}
if (AppInfo.getBoolean(module + ".json.disableInnerClassSerialization", false)) {
gb.disableInnerClassSerialization();
}
if (AppInfo.getBoolean(module + ".json.generateNonExecutableJson", false)) {
gb.generateNonExecutableJson();
}
if (AppInfo.getBoolean(module + ".json.serializeSpecialFloatingPointValues", false)) {
gb.serializeSpecialFloatingPointValues();
}
if (AppInfo.getBoolean(module + ".json.longSerialize2String", true)) {
gb.setLongSerializationPolicy(LongSerializationPolicy.STRING);
}
if (AppInfo.getBoolean(module + ".json.prettyPrinting", false)) {
gb.setPrettyPrinting();
}
return gb;
}
项目:sumk
文件:GsonUtil.java
public static GsonBuilder gsonBuilder(String module) {
if (module == null || module.isEmpty()) {
module = "sumk";
}
DateTimeTypeAdapter da = new DateTimeTypeAdapter();
String format = AppInfo.get(module + ".json.date.format");
if (StringUtil.isNotEmpty(format)) {
da.setDateFormat(format);
}
GsonBuilder gb = new GsonBuilder().registerTypeAdapter(Date.class, da);
if (AppInfo.getBoolean(module + ".json.disableHtmlEscaping", true)) {
gb.disableHtmlEscaping();
}
if (AppInfo.getBoolean(module + ".json.shownull", false)) {
gb.serializeNulls();
}
if (AppInfo.getBoolean(module + ".json.disableInnerClassSerialization", false)) {
gb.disableInnerClassSerialization();
}
if (AppInfo.getBoolean(module + ".json.generateNonExecutableJson", false)) {
gb.generateNonExecutableJson();
}
if (AppInfo.getBoolean(module + ".json.serializeSpecialFloatingPointValues", false)) {
gb.serializeSpecialFloatingPointValues();
}
if (AppInfo.getBoolean(module + ".json.longSerialize2String", false)) {
gb.setLongSerializationPolicy(LongSerializationPolicy.STRING);
}
if (AppInfo.getBoolean(module + ".json.prettyPrinting", false)) {
gb.setPrettyPrinting();
}
DateAdapters.register(gb, module);
return gb;
}
项目: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);
}
项目: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);
}
项目:Camel
文件:GsonDataFormat.java
public LongSerializationPolicy getLongSerializationPolicy() {
return longSerializationPolicy;
}
项目:Camel
文件:GsonDataFormat.java
public void setLongSerializationPolicy(LongSerializationPolicy longSerializationPolicy) {
this.longSerializationPolicy = longSerializationPolicy;
}
项目:hyperdata
文件:HyperDataGsonBuilder.java
/**
* Configures Gson to apply a specific serialization policy for {@code Long} and {@code long}
* objects.
*
* @param serializationPolicy the particular policy to use for serializing longs.
* @return a reference to this {@code HyperDataGsonBuilder} object to fulfill the "Builder" pattern
* @since 1.3
*/
public HyperDataGsonBuilder setLongSerializationPolicy(LongSerializationPolicy serializationPolicy) {
builder.setLongSerializationPolicy(serializationPolicy);
return this;
}