Skip to content
This repository was archived by the owner on Mar 1, 2022. It is now read-only.

Commit f6fea4c

Browse files
Ruinan ZhangRuinan Zhang
authored andcommitted
add gson support
1 parent 0487ff5 commit f6fea4c

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

smoothnlp_maven/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
<version>0.82</version>
4646
</dependency>
4747

48+
<dependency>
49+
<groupId>com.google.code.gson</groupId>
50+
<artifactId>gson</artifactId>
51+
<version>2.8.5</version>
52+
</dependency>
4853

4954
</dependencies>
5055

smoothnlp_maven/smoothnlp.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@
2929
<orderEntry type="library" name="Maven: ml.dmlc:xgboost4j:0.82" level="project" />
3030
<orderEntry type="library" name="Maven: com.typesafe.akka:akka-actor_2.11:2.3.11" level="project" />
3131
<orderEntry type="library" name="Maven: com.typesafe:config:1.2.1" level="project" />
32+
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.5" level="project" />
3233
</component>
3334
</module>

smoothnlp_maven/src/main/java/com/smoothnlp/nlp/basic/UtilFns.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.smoothnlp.nlp.basic;
22

33
import java.util.Arrays;
4+
import com.google.gson.Gson;
5+
import com.google.gson.GsonBuilder;
46

57
public class UtilFns {
68

@@ -41,4 +43,13 @@ public static float[] flatten2dFloatArray(float[][] f2darray){
4143
return output;
4244
}
4345

46+
47+
public static String toJson(Object o){
48+
GsonBuilder gb = new GsonBuilder();
49+
gb = gb.serializeSpecialFloatingPointValues();
50+
gb = gb.serializeNulls();
51+
Gson gson = gb.create();
52+
return gson.toJson(o);
53+
}
54+
4455
}

0 commit comments

Comments
 (0)