Skip to content

Commit

Permalink
Merge pull request #6 from GoodforGod/dev
Browse files Browse the repository at this point in the history
[1.2.0]
  • Loading branch information
GoodforGod authored Jan 18, 2022
2 parents df21b9a + eaf9021 commit 61fdcc1
Show file tree
Hide file tree
Showing 34 changed files with 825 additions and 422 deletions.
18 changes: 17 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,30 @@ root = true
end_of_line = lf
charset = utf-8

# Json
[*.json]
indent_size = 2
indent_style = space
insert_final_newline = false
trim_trailing_whitespace = true

# Yaml
[{*.yml, *.yaml}]
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

# Property files
[*.properties]
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true


# XML files
[*.xml]
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
35 changes: 27 additions & 8 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
# and leave all files detected as binary untouched.
* text=auto

#

# The above will handle all files NOT found below
#
# These files are text and should be normalized (Convert crlf => lf)
*.bash text eol=lf
*.css text diff=css
Expand All @@ -26,16 +25,36 @@
*.xml text
*.yml text eol=lf


# These files are binary and should be left untouched
# (binary is a macro for -text -diff)
*.class binary
# Archives
*.7z binary
*.br binary
*.gz binary
*.tar binary
*.zip binary
*.jar binary
*.so binary
*.war binary
*.dll binary
*.ear binary
*.gif binary

# Documents
*.pdf binary

# Images
*.ico binary
*.jar binary
*.gif binary
*.jpg binary
*.jpeg binary
*.png binary
*.so binary
*.war binary
*.psd binary
*.webp binary

# Fonts
*.woff2 binary

# Other
*.exe binary
*.class binary
*.ear binary
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Package Files #
### Package Files
*.war
*.nar
*.ear
Expand All @@ -9,9 +9,10 @@
### Gradle template
.gradle
build/
target/

# Idea generatted files
### Idea generated files
.idea
/out/
*.iml
.settings/
*.iml
out/
47 changes: 31 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gson configuration and serializers/deserializers for Date/Time in [java.time.*](
**Gradle**
```groovy
dependencies {
implementation "io.goodforgod:gson-configuration:1.1.0"
implementation "io.goodforgod:gson-configuration:1.2.0"
}
```

Expand All @@ -21,7 +21,7 @@ dependencies {
<dependency>
<groupId>io.goodforgod</groupId>
<artifactId>gson-configuration</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
</dependency>
```

Expand All @@ -44,28 +44,36 @@ datetime objects, supported list:
- ZoneId
- ZoneOffset

All adapters register with **ISO8601** formatters by defaults, but you can register them manually with your formatter.
## Formatters

## Formats
Gson Configuration by default comes with [ISO8601 with millis precision](https://goodforgod.dev/posts/2/)
(basically default Java ISO8601 formatters but with millis precision)

Gson Configuration by default comes with [ISO8601](https://en.wikipedia.org/wiki/ISO_8601) with millis precision for all APIs:

Here is list of default formatters for all *java.time.** APIs:
Here is list of such formatters:
- LocalDateTime - *uuuu-MM-dd'T'HH:mm:ss[.SSS]*
- LocalDate - *uuuu-MM-dd*
- LocalTime - *HH:mm:ss[.SSS]*
- OffsetDateTime - *uuuu-MM-dd'T'HH:mm:ss[.SSS]XXX*
- OffsetTime - *HH:mm:ss[.SSS]XXX*
- ZonedDateTime - *uuuu-MM-dd'T'HH:mm:ss[.SSS]XXX[VV]*
- ZonedDateTime - *uuuu-MM-dd'T'HH:mm:ss[.SSS]XXX['['VV']']*

If you want to know more about why use such Java Date & Time formats, you can [read more here](https://goodforgod.dev/posts/2/)

```java
GsonConfiguration configuration = GsonConfiguration.of();
```

If you want to know more about Java Date & Time formats, you can [read more here](https://goodforgod.dev/posts/2/)
You can also use default Java ISO8601 formatters by:
```java
GsonConfiguration configuration = GsonConfiguration.ofJavaISO();
```

## Gson Configuration

Library provides configuration for configuring *GsonBuilder* for most properties:

```java
final GsonBuilder builder = new GsonConfiguration()
GsonBuilder builder = new GsonConfiguration()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
.setInstantFormat("uuuu-MM-dd HH:mm:ss")
.setComplexMapKeySerialization(true)
Expand All @@ -82,7 +90,7 @@ final GsonBuilder builder = new GsonConfiguration()

You can configure DateTimeFormatters for provided adapters:
```java
final GsonBuilder builder = new GsonConfiguration()
GsonBuilder builder = new GsonConfiguration()
.setInstantFormat("uuuu-MM-dd HH:mm:ss")
.builder();
```
Expand All @@ -93,11 +101,11 @@ GsonConfiguration also can be filled from *properties* file.

How to build GsonConfiguration from Properties:
```java
final InputStream resource = getClass().getClassLoader().getResourceAsStream("gson.properties");
final Properties properties = new Properties();
InputStream resource = getClass().getClassLoader().getResourceAsStream("gson.properties");
Properties properties = new Properties();
properties.load(resource);

final GsonConfiguration configuration = GsonConfiguration.ofProperties(properties);
GsonConfiguration configuration = GsonConfiguration.ofProperties(properties);
```

Full list of properties ([check GsonProperties](https://github.com/GoodforGod/gson-configuration/blob/master/src/main/java/io/gson/adapters/config/GsonProperties.java)):
Expand All @@ -114,6 +122,9 @@ gson.format.yearMonth=uuuu-MM
gson.format.monthDay=MM-dd
gson.format.date=yyyy-MM-dd'T'HH:mm:ss.SSSXXX

gson.forceIsoChronology=true
gson.forceResolverStrict=true

gson.lenient=true
gson.serializeNulls=true
gson.prettyPrinting=true
Expand All @@ -131,11 +142,15 @@ gson.policy.longSerialization=STRING
Gson can also be instantiated via properties using *GsonFactory*.

*GsonFactory* is looking for property file in root *resource*: **gson.properties**

```java
Gson gson = new GsonFactory().build();
```

There is respected method to build Gson with Java ISO8601 formatters as defaults:
```java
Gson gson = new GsonFactory().buildJavaISO();
```

## Gson Builder

All adapters already registered via when using *GsonConfiguration#builder*.
Expand All @@ -149,7 +164,7 @@ GsonBuilder builder = GsonAdapters.builder();
You can register them manually:
```java
GsonBuilder builder = new GsonBuilder()
.registerTypeAdapter(LocalDate.class, new LocalDateSerializer())
.registerTypeAdapter(LocalDate.class, LocalDateSerializer.INSTANCE)
```

You can register with custom formatter also:
Expand Down
42 changes: 21 additions & 21 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id "java-library"

id "org.sonarqube" version "3.3"
id "com.diffplug.spotless" version "5.14.3"
id "com.diffplug.spotless" version "6.1.0"
}

repositories {
Expand All @@ -19,29 +19,12 @@ version = artifactVersion
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

spotless {
java {
encoding("UTF-8")
importOrder()
removeUnusedImports()
eclipse().configFile("${projectDir}/config/codestyle.xml")
}
}

sonarqube {
properties {
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.organization", "goodforgod"
property "sonar.projectKey", "GoodforGod_gson-configuration"
}
}

dependencies {
api "com.google.code.gson:gson:2.8.9"

testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.8.1"
testImplementation "org.junit.jupiter:junit-jupiter-api:5.8.1"
testImplementation "org.junit.jupiter:junit-jupiter-params:5.8.1"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.8.2"
testImplementation "org.junit.jupiter:junit-jupiter-api:5.8.2"
testImplementation "org.junit.jupiter:junit-jupiter-params:5.8.2"
}

test {
Expand All @@ -57,6 +40,23 @@ test {
}
}

spotless {
java {
encoding("UTF-8")
importOrder()
removeUnusedImports()
eclipse().configFile("${projectDir}/config/codestyle.xml")
}
}

sonarqube {
properties {
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.organization", "goodforgod"
property "sonar.projectKey", "GoodforGod_gson-configuration"
}
}

publishing {
publications {
mavenJava(MavenPublication) {
Expand Down
Loading

0 comments on commit 61fdcc1

Please sign in to comment.