generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save LocalDate as Oson Date. Update README.md
- Loading branch information
1 parent
f2d524e
commit 49323fe
Showing
7 changed files
with
150 additions
and
24 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
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
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
65 changes: 65 additions & 0 deletions
65
...jackson-oson/src/main/java/oracle/jdbc/provider/oson/deser/OsonLocalDateDeserializer.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,65 @@ | ||
package oracle.jdbc.provider.oson.deser; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer; | ||
import oracle.jdbc.provider.oson.OsonParser; | ||
import oracle.sql.json.OracleJsonParser; | ||
|
||
import java.io.IOException; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class OsonLocalDateDeserializer extends LocalDateDeserializer { | ||
public static final OsonLocalDateDeserializer INSTANCE = new OsonLocalDateDeserializer(); | ||
public OsonLocalDateDeserializer() { | ||
super(); | ||
} | ||
public OsonLocalDateDeserializer(DateTimeFormatter dateFormat) { | ||
super(dateFormat); | ||
} | ||
|
||
public OsonLocalDateDeserializer(OsonLocalDateDeserializer base, DateTimeFormatter dtf) { | ||
super(base, dtf); | ||
} | ||
|
||
public OsonLocalDateDeserializer(OsonLocalDateDeserializer base, Boolean leniency) { | ||
super(base, leniency); | ||
} | ||
|
||
public OsonLocalDateDeserializer(OsonLocalDateDeserializer base, JsonFormat.Shape shape) { | ||
super(base, shape); | ||
} | ||
|
||
@Override | ||
protected OsonLocalDateDeserializer withDateFormat(DateTimeFormatter dtf) { | ||
return new OsonLocalDateDeserializer(dtf); | ||
} | ||
|
||
@Override | ||
protected OsonLocalDateDeserializer withShape(JsonFormat.Shape shape) { | ||
return new OsonLocalDateDeserializer(this,shape); | ||
} | ||
|
||
@Override | ||
public LocalDate deserialize(JsonParser parser, DeserializationContext context) throws IOException { | ||
if(_shape != null || _formatter!= DateTimeFormatter.ISO_LOCAL_DATE) | ||
return super.deserialize(parser, context); | ||
|
||
if (parser instanceof OsonParser) { | ||
OsonParser _parser = (OsonParser) parser; | ||
|
||
if(_parser.currentOsonEvent().equals(OracleJsonParser.Event.VALUE_DATE)) { | ||
LocalDateTime dateTime = _parser.getLocalDateTime(); | ||
LocalDate localDate = dateTime.toLocalDate(); | ||
return localDate; | ||
} | ||
} | ||
else { | ||
return super.deserialize(parser, context); | ||
} | ||
return super.deserialize(parser, context); | ||
} | ||
} |
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
49 changes: 49 additions & 0 deletions
49
...der-jackson-oson/src/main/java/oracle/jdbc/provider/oson/ser/OsonLocalDateSerializer.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,49 @@ | ||
package oracle.jdbc.provider.oson.ser; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; | ||
import oracle.jdbc.provider.oson.OsonGenerator; | ||
|
||
import java.io.IOException; | ||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
public class OsonLocalDateSerializer extends LocalDateSerializer { | ||
|
||
public static final OsonLocalDateSerializer INSTANCE = new OsonLocalDateSerializer(); | ||
|
||
public OsonLocalDateSerializer() { | ||
super(); | ||
} | ||
|
||
public OsonLocalDateSerializer(OsonLocalDateSerializer base, Boolean useTimestamp, | ||
DateTimeFormatter dtf, JsonFormat.Shape shape) { | ||
super(base, useTimestamp, dtf, shape); | ||
} | ||
|
||
public OsonLocalDateSerializer(DateTimeFormatter formatter) { | ||
super(formatter); | ||
} | ||
|
||
@Override | ||
protected OsonLocalDateSerializer withFormat(Boolean useTimestamp, DateTimeFormatter dtf, JsonFormat.Shape shape) { | ||
return new OsonLocalDateSerializer(this, useTimestamp, dtf, shape); | ||
} | ||
|
||
@Override | ||
public void serialize(LocalDate date, JsonGenerator g, SerializerProvider provider) throws IOException { | ||
if(_formatter != null || _shape != null) { | ||
super.serialize(date, g, provider); | ||
return; | ||
} | ||
if (g instanceof OsonGenerator) { | ||
OsonGenerator generator = (OsonGenerator) g; | ||
generator.writeLocalDate(date); | ||
return; | ||
}else { | ||
super.serialize(date, g, provider); | ||
} | ||
} | ||
} |