-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using Module for DateTime Extension.
- Loading branch information
Showing
6 changed files
with
101 additions
and
0 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,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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"> | ||
<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>jr-extension-datetime</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>20</maven.compiler.source> | ||
<maven.compiler.target>20</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.jr</groupId> | ||
<artifactId>jackson-jr-objects</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
11 changes: 11 additions & 0 deletions
11
.../main/java/com/fasterxml/jackson/jr/extension/datetime/JacksonLocalDateTimeExtension.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,11 @@ | ||
package com.fasterxml.jackson.jr.extension.datetime; | ||
|
||
import com.fasterxml.jackson.jr.ob.JacksonJrExtension; | ||
import com.fasterxml.jackson.jr.ob.api.ExtensionContext; | ||
|
||
public class JacksonLocalDateTimeExtension extends JacksonJrExtension { | ||
@Override | ||
protected void register(ExtensionContext ctxt) { | ||
ctxt.insertProvider(new LocalDateTimeReaderWriterProvider()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...n/java/com/fasterxml/jackson/jr/extension/datetime/LocalDateTimeReaderWriterProvider.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,21 @@ | ||
package com.fasterxml.jackson.jr.extension.datetime; | ||
|
||
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; | ||
|
||
public class LocalDateTimeReaderWriterProvider extends ReaderWriterProvider { | ||
@Override | ||
public ValueReader findValueReader(JSONReader readContext, Class<?> type) { | ||
return type.equals(LocalDateTime.class) ? new LocalDateTimeValueReader() : null; | ||
} | ||
|
||
@Override | ||
public ValueWriter findValueWriter(JSONWriter writeContext, Class<?> type) { | ||
return type.equals(LocalDateTime.class) ? new LocalDateTimeValueWriter() : null; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...e/src/main/java/com/fasterxml/jackson/jr/extension/datetime/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,20 @@ | ||
package com.fasterxml.jackson.jr.extension.datetime; | ||
|
||
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 { | ||
public LocalDateTimeValueReader() { | ||
super(LocalDateTime.class); | ||
} | ||
|
||
@Override | ||
public Object read(JSONReader reader, JsonParser p) throws IOException { | ||
return LocalDateTime.parse(p.getText(), DateTimeFormatter.ISO_LOCAL_DATE_TIME); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...e/src/main/java/com/fasterxml/jackson/jr/extension/datetime/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,22 @@ | ||
package com.fasterxml.jackson.jr.extension.datetime; | ||
|
||
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 { | ||
@Override | ||
public void writeValue(JSONWriter context, JsonGenerator g, Object value) throws IOException { | ||
String localDateTimeString = ((LocalDateTime) value).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME); | ||
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