Skip to content

Commit b4c549a

Browse files
authored
Merge pull request #105 from geniejhang/vtype-gson
Gson de/serializer for vtype
2 parents 8434259 + 15528c9 commit b4c549a

47 files changed

Lines changed: 2751 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

epics-vtype/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<modules>
1818
<module>vtype</module>
1919
<module>vtype-json</module>
20+
<module>vtype-gson</module>
2021
</modules>
2122
<build>
2223
<!-- Reset to standard source directories -->

epics-vtype/vtype-gson/pom.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>8</source><target>8</target></configuration></plugin></plugins></build>
4+
<parent>
5+
<groupId>org.epics</groupId>
6+
<artifactId>epics-vtype-all</artifactId>
7+
<version>1.0.4-SNAPSHOT</version>
8+
</parent>
9+
<artifactId>vtype-gson</artifactId>
10+
<name>org.epics.vtype.gson</name>
11+
<description>Google GSON de/serializer for value types.</description>
12+
<dependencies>
13+
<dependency>
14+
<groupId>${project.groupId}</groupId>
15+
<artifactId>vtype</artifactId>
16+
<version>${project.version}</version>
17+
</dependency>
18+
<dependency>
19+
<groupId>com.google.code.gson</groupId>
20+
<artifactId>gson</artifactId>
21+
<version>2.8.6</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>javax.ws.rs</groupId>
25+
<artifactId>javax.ws.rs-api</artifactId>
26+
<version>2.1</version>
27+
<scope>compile</scope>
28+
</dependency>
29+
</dependencies>
30+
</project>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright (C) 2020 Facility for Rare Isotope Beams
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*
17+
* Contact Information: Facility for Rare Isotope Beam,
18+
* Michigan State University,
19+
* East Lansing, MI 48824-1321
20+
* http://frib.msu.edu
21+
*/
22+
package org.epics.vtype.gson;
23+
24+
import com.google.gson.Gson;
25+
import com.google.gson.GsonBuilder;
26+
import org.epics.vtype.VType;
27+
28+
import java.text.DecimalFormat;
29+
import java.util.Date;
30+
31+
/**
32+
* Custom Gson object creator having some TypeAdapters and options
33+
*
34+
* @author <a href="mailto:changj@frib.msu.edu">Genie Jhang</a>
35+
*/
36+
37+
public class CustomGson {
38+
public static Gson getGson() {
39+
return new GsonBuilder()
40+
.registerTypeAdapter(VType.class, new GsonVTypeHandler())
41+
.registerTypeAdapter(Date.class, new GsonDateHandler())
42+
.registerTypeAdapter(DecimalFormat.class, new GsonDecimalFormatHandler())
43+
.serializeNulls()
44+
.serializeSpecialFloatingPointValues()
45+
.create();
46+
}
47+
}

0 commit comments

Comments
 (0)