forked from FasterXML/jackson-jr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2.17' into issue-FasterXML#93
- Loading branch information
Showing
46 changed files
with
940 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
groups: | ||
github-actions: | ||
patterns: | ||
- "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,14 +22,14 @@ jobs: | |
strategy: | ||
fail-fast: false | ||
matrix: | ||
java_version: ['8', '11', '17'] | ||
java_version: ['8', '11', '17', '21'] | ||
os: ['ubuntu-20.04'] | ||
env: | ||
JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1" | ||
steps: | ||
- uses: actions/[email protected].0 | ||
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | ||
- name: Set up JDK | ||
uses: actions/setup-java@v3 | ||
uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4.0.0 | ||
with: | ||
distribution: 'temurin' | ||
java-version: ${{ matrix.java_version }} | ||
|
@@ -57,7 +57,7 @@ jobs: | |
run: ./mvnw -B -q -ff -ntp test | ||
- name: Publish code coverage | ||
if: github.event_name != 'pull_request' && matrix.java_version == '8' | ||
uses: codecov/codecov-action@v1 | ||
uses: codecov/codecov-action@e0b68c6749509c5f83f984dd99a76a1c1a231044 # v4.0.1 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
file: ./target/site/jacoco/jacoco.xml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,18 @@ | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip | ||
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.3/apache-maven-3.9.3-bin.zip | ||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
## Overview | ||
|
||
This module extends the functionality of jackson-jr by adding support for (a subset of) Java 8 Date/Time types (value types in JDK `java.time` package). | ||
|
||
### Status | ||
|
||
Added in Jackson 2.17. | ||
|
||
### Usage | ||
To be able to use supported annotations, you need to register extension like so: | ||
```java | ||
private static final JSON JACKSON = JSON.builder() | ||
.register(new JacksonJrJavaTimeExtension()) | ||
.build(); | ||
``` | ||
after which you can use normal read and write operations as usual: | ||
|
||
```java | ||
import java.time.LocalDateTime; | ||
|
||
public class Application { | ||
public static void main(String[] args) { | ||
final LocalDateTime now = LocalDateTime.now(); | ||
MyClass myObject = new MyClass(now, 'Some Other Values....'); | ||
String myObjectJsonString = JACKSON.asString(myObject); | ||
MyClass myObjectFromJson = JACKSON.beanFrom(MyClass, myObjectJsonString); | ||
assert myObjectFromJson.getTime().equals(now); | ||
} | ||
} | ||
|
||
// ... | ||
|
||
public class MyClass { | ||
private LocalDateTime time; | ||
private String otherItems; | ||
|
||
public MyClass(LocalDateTime datetime, String others) { | ||
//... | ||
} | ||
|
||
public LocalDateTime getTime() { | ||
return time; | ||
} | ||
// other getters & setters | ||
} | ||
``` | ||
|
||
### Date Classes currently supported by `JacksonJrJavaTimeExtension` | ||
|
||
- `java.util.LocalDateTime` | ||
|
||
### Plans for Future | ||
|
||
- Add support for other Java 8 Date/Time types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<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/maven-v4_0_0.xsd"> | ||
<!-- This module was also published with a richer model, Gradle metadata, --> | ||
<!-- which should be used instead. Do not delete the following line which --> | ||
<!-- is to indicate to Gradle or any Gradle module metadata file consumer --> | ||
<!-- that they should prefer consuming it instead. --> | ||
<!-- do_not_remove: published-with-gradle-metadata --> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.fasterxml.jackson.jr</groupId> | ||
<artifactId>jackson-jr-parent</artifactId> | ||
<version>2.17.0-rc1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>jackson-jr-extension-javatime</artifactId> | ||
<packaging>bundle</packaging> | ||
<description>Jackson-jr extension that adds support for Java 8 Date/Time value types such as `java.util.LocalDateTime`</description> | ||
<url>https://github.com/FasterXML/jackson-jr</url> | ||
|
||
<licenses> | ||
<license> | ||
<name>The Apache Software License, Version 2.0</name> | ||
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
|
||
<properties> | ||
<!-- Looks like we need to be bit careful on OSGi exports, to avoid | ||
accidentally double-exporting jr-objects types | ||
--> | ||
<osgi.export>${project.groupId}.extension.javatime;version=${project.version}</osgi.export> | ||
|
||
<!-- for Reproducible Builds --> | ||
<project.build.outputTimestamp>2023-11-15T22:39:39Z</project.build.outputTimestamp> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.jr</groupId> | ||
<artifactId>jackson-jr-objects</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<redirectTestOutputToFile>${surefire.redirectTestOutputToFile}</redirectTestOutputToFile> | ||
<excludes> | ||
<exclude>**/failing/*.java</exclude> | ||
</excludes> | ||
</configuration> | ||
</plugin> | ||
<!-- 11-Mar-2019, tatu: Add basic JDK8-includable module-info, generated by Moditect --> | ||
<plugin> | ||
<groupId>org.moditect</groupId> | ||
<artifactId>moditect-maven-plugin</artifactId> | ||
</plugin> | ||
<!-- 05-Jul-2020, tatu: Add generation of Gradle Module Metadata --> | ||
<plugin> | ||
<groupId>de.jjohannes</groupId> | ||
<artifactId>gradle-module-metadata-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
20 changes: 20 additions & 0 deletions
20
...src/main/java/com/fasterxml/jackson/jr/extension/javatime/JacksonJrJavaTimeExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.fasterxml.jackson.jr.extension.javatime; | ||
|
||
import com.fasterxml.jackson.jr.ob.JacksonJrExtension; | ||
import com.fasterxml.jackson.jr.ob.api.ExtensionContext; | ||
|
||
public class JacksonJrJavaTimeExtension extends JacksonJrExtension { | ||
final static JavaTimeReaderWriterProvider DEFAULT_RW_PROVIDER = new JavaTimeReaderWriterProvider(); | ||
|
||
private JavaTimeReaderWriterProvider readerWriterProvider = DEFAULT_RW_PROVIDER; | ||
|
||
@Override | ||
protected void register(ExtensionContext ctxt) { | ||
ctxt.insertProvider(readerWriterProvider); | ||
} | ||
|
||
public JacksonJrJavaTimeExtension with(JavaTimeReaderWriterProvider p) { | ||
readerWriterProvider = p; | ||
return this; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...c/main/java/com/fasterxml/jackson/jr/extension/javatime/JavaTimeReaderWriterProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.fasterxml.jackson.jr.extension.javatime; | ||
|
||
import com.fasterxml.jackson.jr.ob.api.ReaderWriterProvider; | ||
import com.fasterxml.jackson.jr.ob.api.ValueReader; | ||
import com.fasterxml.jackson.jr.ob.api.ValueWriter; | ||
import com.fasterxml.jackson.jr.ob.impl.JSONReader; | ||
import com.fasterxml.jackson.jr.ob.impl.JSONWriter; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
/** | ||
* Provider for {@link ValueReader}s and {@link ValueWriter}s for Date/Time | ||
* types supported by Java Time Extension. | ||
*/ | ||
public class JavaTimeReaderWriterProvider extends ReaderWriterProvider | ||
{ | ||
private DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME; | ||
|
||
public JavaTimeReaderWriterProvider() { } | ||
|
||
@Override | ||
public ValueReader findValueReader(JSONReader readContext, Class<?> type) { | ||
return LocalDateTime.class.isAssignableFrom(type) ? new LocalDateTimeValueReader(dateTimeFormatter) : null; | ||
} | ||
|
||
@Override | ||
public ValueWriter findValueWriter(JSONWriter writeContext, Class<?> type) { | ||
return LocalDateTime.class.isAssignableFrom(type) ? new LocalDateTimeValueWriter(dateTimeFormatter) : null; | ||
} | ||
|
||
/** | ||
* Method for reconfiguring {@link DateTimeFormatter} used for reading/writing | ||
* following Date/Time value types: | ||
*<ul> | ||
* <li>{@code java.time.LocalDateTime} | ||
* </li> | ||
*</ul> | ||
* | ||
* @param formatter | ||
* | ||
* @return This provider instance for call chaining | ||
*/ | ||
public JavaTimeReaderWriterProvider withDateTimeFormatter(DateTimeFormatter formatter) { | ||
dateTimeFormatter = formatter; | ||
return this; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...e/src/main/java/com/fasterxml/jackson/jr/extension/javatime/LocalDateTimeValueReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.fasterxml.jackson.jr.extension.javatime; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.jr.ob.api.ValueReader; | ||
import com.fasterxml.jackson.jr.ob.impl.JSONReader; | ||
|
||
import java.io.IOException; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class LocalDateTimeValueReader extends ValueReader { | ||
private final DateTimeFormatter formatter; | ||
|
||
public LocalDateTimeValueReader(DateTimeFormatter formatter) { | ||
super(LocalDateTime.class); | ||
this.formatter = formatter; | ||
} | ||
|
||
@Override | ||
public Object read(JSONReader reader, JsonParser p) throws IOException { | ||
return LocalDateTime.parse(p.getText(), formatter); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...e/src/main/java/com/fasterxml/jackson/jr/extension/javatime/LocalDateTimeValueWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.fasterxml.jackson.jr.extension.javatime; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.jr.ob.api.ValueWriter; | ||
import com.fasterxml.jackson.jr.ob.impl.JSONWriter; | ||
|
||
import java.io.IOException; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class LocalDateTimeValueWriter implements ValueWriter { | ||
private final DateTimeFormatter formatter; | ||
|
||
public LocalDateTimeValueWriter(DateTimeFormatter formatter) { | ||
this.formatter = formatter; | ||
} | ||
|
||
@Override | ||
public void writeValue(JSONWriter context, JsonGenerator g, Object value) throws IOException { | ||
String localDateTimeString = ((LocalDateTime) value).format(formatter); | ||
context.writeValue(localDateTimeString); | ||
} | ||
|
||
@Override | ||
public Class<?> valueType() { | ||
return LocalDateTime.class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
This copy of Jackson-jr library is licensed under the | ||
Apache (Software) License, version 2.0 ("the License"). | ||
See the License for details about distribution rights, and the | ||
specific rights regarding derivative works. | ||
|
||
You may obtain a copy of the License at: | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Jackson JSON processor | ||
|
||
Jackson is a high-performance, Free/Open Source JSON processing library. | ||
It was originally written by Tatu Saloranta ([email protected]), and has | ||
been in development since 2007. | ||
It is currently developed by a community of developers. | ||
|
||
## Licensing | ||
|
||
Jackson components are licensed under Apache (Software) License, version 2.0, | ||
as per accompanying LICENSE file. | ||
|
||
## Credits | ||
|
||
A list of contributors may be found from CREDITS file, which is included | ||
in some artifacts (usually source distributions); but is always available | ||
from the source code management (SCM) system project uses. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module com.fasterxml.jackson.jr.extension.javatime { | ||
requires com.fasterxml.jackson.core; | ||
requires com.fasterxml.jackson.jr.ob; | ||
|
||
exports com.fasterxml.jackson.jr.extension.javatime; | ||
} |
Oops, something went wrong.