Skip to content

Commit

Permalink
Minor renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 19, 2024
1 parent 7554263 commit fa656f7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
13 changes: 6 additions & 7 deletions jr-extension-javatime/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
## Overview

This module extends the functionalities of jackson-jr adding support for a subset of Java 8 Date & Time objects such as `LocalDateTime` & `DateTime`.
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
Expand All @@ -15,20 +16,16 @@ To be able to use supported annotations, you need to register extension like so:
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);
}

}

// ...
Expand All @@ -49,7 +46,9 @@ public class MyClass {
```

### Date Classes currently supported by `JacksonJavaTimeExtension`
- LocalDateTime

- `java.util.LocalDateTime`

### Plans for Future
- Other Java 8 DateTime classes

- Add support for other Java 8 Date/Time types
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.fasterxml.jackson.jr.ob.JacksonJrExtension;
import com.fasterxml.jackson.jr.ob.api.ExtensionContext;

public class JacksonJavaTimeExtension extends JacksonJrExtension {
public class JacksonJrJavaTimeExtension extends JacksonJrExtension {
@Override
protected void register(ExtensionContext ctxt) {
ctxt.insertProvider(new JacksonJavaTimeReaderWriterProvider());
ctxt.insertProvider(new JavaTimeReaderWriterProvider());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class JacksonJavaTimeReaderWriterProvider extends ReaderWriterProvider {
public class JavaTimeReaderWriterProvider extends ReaderWriterProvider {
private DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;

@Override
public ValueReader findValueReader(JSONReader readContext, Class<?> type) {
return type.equals(LocalDateTime.class) ? new JacksonJavaTimeValueReader(formatter) : null;
return type.equals(LocalDateTime.class) ? new JavaTimeValueReader(formatter) : null;
}

@Override
public ValueWriter findValueWriter(JSONWriter writeContext, Class<?> type) {
return type.equals(LocalDateTime.class) ? new JacksonJavaTimeValueWriter(formatter) : null;
return type.equals(LocalDateTime.class) ? new JavaTimeValueWriter(formatter) : null;
}

public JacksonJavaTimeReaderWriterProvider withFormatter(DateTimeFormatter formatter) {
public JavaTimeReaderWriterProvider withFormatter(DateTimeFormatter formatter) {
this.formatter = formatter;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class JacksonJavaTimeValueReader extends ValueReader {
public class JavaTimeValueReader extends ValueReader {
private final DateTimeFormatter formatter;

public JacksonJavaTimeValueReader(DateTimeFormatter formatter) {
public JavaTimeValueReader(DateTimeFormatter formatter) {
super(LocalDateTime.class);
this.formatter = formatter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class JacksonJavaTimeValueWriter implements ValueWriter {
public class JavaTimeValueWriter implements ValueWriter {
private final DateTimeFormatter formatter;

public JacksonJavaTimeValueWriter(DateTimeFormatter formatter) {
public JavaTimeValueWriter(DateTimeFormatter formatter) {
this.formatter = formatter;
}

Expand Down

0 comments on commit fa656f7

Please sign in to comment.