List of usage examples for com.google.gson LongSerializationPolicy STRING
LongSerializationPolicy STRING
To view the source code for com.google.gson LongSerializationPolicy STRING.
Click Source Link
From source file:com.ibm.og.client.ApacheClient.java
License:Open Source License
private Gson createGson() { return new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .setLongSerializationPolicy(LongSerializationPolicy.STRING) .registerTypeAdapter(Double.class, new TypeAdapter<Double>() { @Override//from w ww. jav a2 s.c om public void write(final JsonWriter out, final Double value) throws IOException { // round decimals to 2 places out.value(new BigDecimal(value).setScale(2, RoundingMode.HALF_UP).doubleValue()); } @Override public Double read(final JsonReader in) throws IOException { return in.nextDouble(); } }.nullSafe()).create(); }
From source file:io.weba.processor.flink.event.gson.factory.EventFactory.java
License:Open Source License
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();/* w w w . jav a 2 s. c om*/ 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(); }
From source file:org.eclipse.packagedrone.repo.channel.apm.ChannelModelProvider.java
License:Open Source License
static Gson createGson() { final GsonBuilder builder = new GsonBuilder(); builder.setPrettyPrinting();// ww w . j av a 2s . c o m 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(); }
From source file:org.fracturedatlas.athena.audit.serialization.AuditMessageArraySerializer.java
License:Open Source License
@Override public void writeTo(AuditMessage[] messages, Class<?> type, Type type1, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream out) throws IOException, WebApplicationException { Gson gson = new GsonBuilder().setLongSerializationPolicy(LongSerializationPolicy.STRING).create(); out.write(gson.toJson(messages).getBytes()); // JsonArray valueArray = new JsonArray(); // JsonObject jsonAuditMessage = null; // for (AuditMessage value : values) { // jsonAuditMessage = new JsonObject(); // jsonAuditMessage.addProperty("id", value.getId()); // jsonAuditMessage.addProperty("dateTime", value.getDateTime()); // jsonAuditMessage.addProperty("User", value.getUser()); // jsonAuditMessage.addProperty("Action", value.getAction()); // jsonAuditMessage.addProperty("Resource", value.getResource()); // jsonAuditMessage.addProperty("Message", value.getMessage()); ///*from w w w.j a va 2 s . co m*/ // valueArray.add(jsonAuditMessage); // } // out.write(valueArray.toString().getBytes()); }
From source file:org.jc.avrotokudu.consumer.AvroConsumer.java
public AvroConsumer(String consumerGroup, String topic, int partitionToConsume, String[] seedBrokers, int soTimeout, int port, int maxEmptyPartitionReadTries, String tableName, String[] masterAddresses) { super(consumerGroup, topic, partitionToConsume, seedBrokers, soTimeout, port, maxEmptyPartitionReadTries); GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setLongSerializationPolicy(LongSerializationPolicy.STRING); this.gson = gsonBuilder.create(); try {/*w w w. j a v a2s . c om*/ AvroConsumer.kuduHelper = KuduHelperFactory.buildKuduHelper(tableName, masterAddresses); AvroConsumer.kuduHelper.init(KuduHelper.KUDU_SESSION_ASYNC, SessionConfiguration.FlushMode.AUTO_FLUSH_BACKGROUND); } catch (Exception ex) { Logger.getLogger(AvroConsumer.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.jc.kududbhelper.lib.KuduHelper.java
/** * Method to process data in a json array. Usually invoked when invoking * from cli commands. Notice that when KuduHelper is included as an external * jar inside a given project, this is not the preferred method. * * @param jsonArray an array of json objects with the format * Map<String, String>// w w w . j ava 2 s. c o m * @throws InterruptedException This exception indicates that an async kudu * table did not successfully joined within timeout millis. * @throws Exception An exception when inserting data, parsing values to be * inserted or invalid data types. */ public void processJson(String jsonArray) throws InterruptedException, IllegalStateException, Exception { GsonBuilder gsonBuilder = new GsonBuilder(); java.lang.reflect.Type type = new TypeToken<List<Map<String, String>>>() { }.getType(); gsonBuilder.setLongSerializationPolicy(LongSerializationPolicy.STRING); Gson gson = gsonBuilder.create(); List<Map<String, String>> data = gson.fromJson(jsonArray, type); if (data.isEmpty()) { throw new Exception("Cannot process an empty data list."); } this.processObjectsAsMap(data); }
From source file:qunar.tc.qmq.producer.tx.spring.DefaultMessageStore.java
License:Apache License
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; this.sqlStatementProvider = new DefaultSqlStatementProvider(); }