Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save java.util.Date as "OSON TimeStamp" to preserve Time part. #146

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ojdbc-provider-jackson-oson/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ in order to use the Oracle JDBC driver's JSON processing capabilities. It, there
- **Java Types Handling**: Support for various complex and basic Java types during serialization and deserialization.
- **Jackson Annotation support**: Support for Jackson Annotations. Note: When **@Format** annotation is used, the values are processed as Strings.

## Java type to Oson Mappings
## Java type to OSON Mappings
When the **OSON Provider for Jackson** is used the Java types are stored as their corresponding OSON types. The type
mapping is given by the following table.

| **Java Type** | **Oson Type** |
| **Java Type** | **OSON Type** |
|--------------------------------------------|--------------------|
| `LocalDateTime` | `OSON TIMESTAMP` |
| `OffsetDateTime` | `OSON TIMESTAMPTZ` |
Expand All @@ -27,7 +27,7 @@ mapping is given by the following table.
| `BigInteger` | `OSON NUMBER` |
| `Year` | `OSON NUMBER` |
| `byte[]` | `OSON byte[]` |
| `java.util.Date` | `OSON DATE` |
| `java.util.Date` | `OSON TIMESTAMP` |
| `java.sql.Date` | `OSON DATE` |
| `Timestamp` | `OSON TIMESTAMP` |
| `LocalDate` | `OSON DATE` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,10 @@ public void writeDate(Date value) throws IOException {
}else {
// java.util.Date
logger.log(Level.FINEST, "writeDate: java.util.Date");
DATE dd = new DATE(new java.sql.Date(value.getTime()));
OracleJsonDate jsonDate = new OracleJsonDateImpl(dd.shareBytes());
gen.write(jsonDate);
Timestamp ts = new Timestamp(value.getTime());
TIMESTAMP timestamp = new TIMESTAMP(ts);
OracleJsonTimestamp writeTimeStamp = new OracleJsonTimestampImpl(timestamp.shareBytes());
gen.write(writeTimeStamp);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ public class Employee {
*/
private Date hireDate;

/**
* The date the employee was hired in java.util.Date.
*/
private java.util.Date hireUtilDate;

/**
* The LocalDate the employee was hired.
*/
Expand Down Expand Up @@ -261,7 +266,7 @@ public Employee(int employeeId, BigDecimal salary, BigInteger largeNumber, Strin
long logoutTime, ZonedDateTime vacationZonedDateTime, short deptId, long employeeCode, byte grade,
float bonus, double prevSalary, char gender, Period totalPeriod, Integer idBoxed, Boolean isActiveBoxed,
Byte rankBoxed, Character genderBoxed, Short ageBoxed, Long salaryBoxed, Float performanceScoreBoxed,
Double bonusBoxed) {
Double bonusBoxed, java.util.Date hireUtilDate) {
this.employeeId = employeeId;
this.salary = salary;
this.largeNumber = largeNumber;
Expand Down Expand Up @@ -302,6 +307,7 @@ public Employee(int employeeId, BigDecimal salary, BigInteger largeNumber, Strin
this.salaryBoxed = salaryBoxed;
this.performanceScoreBoxed = performanceScoreBoxed;
this.bonusBoxed = bonusBoxed;
this.hireUtilDate = hireUtilDate;
}

// Getters and Setters
Expand Down Expand Up @@ -940,6 +946,16 @@ public void setBonusBoxed(Double bonusBoxed) {
this.bonusBoxed = bonusBoxed;
}

public java.util.Date getHireUtilDate() {
return hireUtilDate;
}

public void setHireUtilDate(java.util.Date hireUtilDate) {
this.hireUtilDate = hireUtilDate;
}




/**
* Provides a string representation of the Employee object.
Expand All @@ -950,18 +966,26 @@ public void setBonusBoxed(Double bonusBoxed) {
public String toString() {
return "Employee{" +
"employeeId=" + employeeId +
", logoutTime=" + logoutTime +
", active=" + active +
", deptId=" + deptId +
", employeeCode=" + employeeCode +
", grade=" + grade +
", bonus=" + bonus +
", prevSalary=" + prevSalary +
", gender=" + gender +
", salary=" + salary +
", largeNumber=" + largeNumber +
", firstName='" + firstName + '\'' +
", middleInitial='" + middleInitial + '\'' +
", lastName='" + lastName + '\'' +
", hireDate=" + hireDate +
", hireUtilDate=" + hireUtilDate +
", localHireDate=" + localHireDate +
", loginInstant=" + loginInstant +
", loginLocalTime=" + loginLocalTime +
", salaryMonthDay=" + salaryMonthDay +
", incrementYearmonth=" + incrementYearmonth +
", logoutTime=" + logoutTime +
", startTime=" + startTime +
", lastUpdated=" + lastUpdated +
", localDateTime=" + localDateTime +
Expand All @@ -970,16 +994,9 @@ public String toString() {
", durationOfEmployment=" + durationOfEmployment +
", picture=" + Arrays.toString(picture) +
", resume='" + resume + '\'' +
", active=" + active +
", rawData=" + Arrays.toString(rawData) +
", phones=" + phones +
", vacationZonedDateTime=" + vacationZonedDateTime +
", deptId=" + deptId +
", employeeCode=" + employeeCode +
", grade=" + grade +
", bonus=" + bonus +
", gender=" + gender +
", prevSalary=" + prevSalary +
", totalPeriod=" + totalPeriod +
", idBoxed=" + idBoxed +
", isActiveBoxed=" + isActiveBoxed +
Expand All @@ -993,41 +1010,58 @@ public String toString() {
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Employee employee = (Employee) o;
return employeeId == employee.employeeId && logoutTime == employee.logoutTime && active == employee.active
&& deptId == employee.deptId && employeeCode == employee.employeeCode && grade == employee.grade
&& Float.compare(bonus, employee.bonus) == 0 && Double.compare(prevSalary, employee.prevSalary) == 0
public boolean equals(Object object) {
if (this == object) return true;
if (object == null || getClass() != object.getClass()) return false;
Employee employee = (Employee) object;
return employeeId == employee.employeeId && logoutTime == employee.logoutTime
&& active == employee.active && deptId == employee.deptId
&& employeeCode == employee.employeeCode && grade == employee.grade
&& Float.compare(bonus, employee.bonus) == 0
&& Double.compare(prevSalary, employee.prevSalary) == 0
&& gender == employee.gender && Objects.equals(salary, employee.salary)
&& Objects.equals(largeNumber, employee.largeNumber) && Objects.equals(firstName, employee.firstName)
&& Objects.equals(middleInitial, employee.middleInitial) && Objects.equals(lastName, employee.lastName)
&& Objects.equals(hireDate, employee.hireDate) && Objects.equals(localHireDate, employee.localHireDate)
&& Objects.equals(loginInstant, employee.loginInstant) && Objects.equals(loginLocalTime, employee.loginLocalTime)
&& Objects.equals(largeNumber, employee.largeNumber)
&& Objects.equals(firstName, employee.firstName)
&& Objects.equals(middleInitial, employee.middleInitial)
&& Objects.equals(lastName, employee.lastName)
&& Objects.equals(hireDate, employee.hireDate)
&& Objects.equals(hireUtilDate, employee.hireUtilDate)
&& Objects.equals(localHireDate, employee.localHireDate)
&& Objects.equals(loginInstant, employee.loginInstant)
&& Objects.equals(loginLocalTime, employee.loginLocalTime)
&& Objects.equals(salaryMonthDay, employee.salaryMonthDay)
&& Objects.equals(incrementYearmonth, employee.incrementYearmonth)
&& Objects.equals(startTime, employee.startTime) && Objects.equals(lastUpdated, employee.lastUpdated)
&& Objects.equals(localDateTime, employee.localDateTime) && Objects.equals(offsetDateTime, employee.offsetDateTime)
&& Objects.equals(yearJoined, employee.yearJoined) && Objects.equals(durationOfEmployment, employee.durationOfEmployment)
&& Objects.equals(resume, employee.resume)
&& Objects.equals(startTime, employee.startTime)
&& Objects.equals(lastUpdated, employee.lastUpdated)
&& Objects.equals(localDateTime, employee.localDateTime)
&& Objects.equals(offsetDateTime, employee.offsetDateTime)
&& Objects.equals(yearJoined, employee.yearJoined)
&& Objects.equals(durationOfEmployment, employee.durationOfEmployment)
&& Objects.deepEquals(picture, employee.picture)
&& Objects.equals(resume, employee.resume)
&& Objects.deepEquals(rawData, employee.rawData)
&& Objects.equals(phones, employee.phones)
&& Objects.equals(vacationZonedDateTime, employee.vacationZonedDateTime)
&& Objects.equals(totalPeriod, employee.totalPeriod) && Objects.equals(idBoxed, employee.idBoxed)
&& Objects.equals(isActiveBoxed, employee.isActiveBoxed) && Objects.equals(rankBoxed, employee.rankBoxed)
&& Objects.equals(genderBoxed, employee.genderBoxed) && Objects.equals(ageBoxed, employee.ageBoxed)
&& Objects.equals(salaryBoxed, employee.salaryBoxed) && Objects.equals(performanceScoreBoxed, employee.performanceScoreBoxed)
&& Objects.equals(bonusBoxed, employee.bonusBoxed)
&& Arrays.equals(picture, employee.picture) && Arrays.equals(rawData, employee.rawData);
&& Objects.equals(totalPeriod, employee.totalPeriod)
&& Objects.equals(idBoxed, employee.idBoxed)
&& Objects.equals(isActiveBoxed, employee.isActiveBoxed)
&& Objects.equals(rankBoxed, employee.rankBoxed)
&& Objects.equals(genderBoxed, employee.genderBoxed)
&& Objects.equals(ageBoxed, employee.ageBoxed)
&& Objects.equals(salaryBoxed, employee.salaryBoxed)
&& Objects.equals(performanceScoreBoxed, employee.performanceScoreBoxed)
&& Objects.equals(bonusBoxed, employee.bonusBoxed);
}

@Override
public int hashCode() {
return Objects.hash(employeeId, logoutTime, active, deptId, employeeCode, grade, bonus, prevSalary, gender,
salary, largeNumber, firstName, middleInitial, lastName, hireDate, localHireDate, loginInstant,
loginLocalTime, salaryMonthDay, incrementYearmonth, startTime, lastUpdated, localDateTime, offsetDateTime,
yearJoined, durationOfEmployment, Arrays.hashCode(picture), resume, Arrays.hashCode(rawData), phones,
vacationZonedDateTime, totalPeriod, idBoxed, isActiveBoxed, rankBoxed, genderBoxed, ageBoxed, salaryBoxed,
performanceScoreBoxed, bonusBoxed);
return Objects.hash(employeeId, logoutTime, active, deptId, employeeCode, grade,
bonus, prevSalary, gender, salary, largeNumber, firstName, middleInitial,
lastName, hireDate, hireUtilDate, localHireDate, loginInstant, loginLocalTime,
salaryMonthDay, incrementYearmonth, startTime, lastUpdated, localDateTime,
offsetDateTime, yearJoined, durationOfEmployment,
Arrays.hashCode(picture), resume, Arrays.hashCode(rawData), phones,
vacationZonedDateTime, totalPeriod, idBoxed, isActiveBoxed,
rankBoxed, genderBoxed, ageBoxed, salaryBoxed, performanceScoreBoxed, bonusBoxed);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private static void instantiateEmployees() {
MonthDay.now(), YearMonth.now(), System.currentTimeMillis(), ZonedDateTime.now(ZoneOffset.UTC),(short)101,
1234567890L, (byte)5, 1500.5f, 75000.0, 'M', Period.of(10,10,0),
1, true, (byte) 1, 'M', (short) 25, 50000L,
4.5f, 5000.0));
4.5f, 5000.0, java.util.Date.from(Instant.now())));

employees.add(new Employee(2, new BigDecimal("60000.99"), new BigInteger("987654321"),
"Jane", "B", "Smith", Date.valueOf("2016-02-20"), Time.valueOf("08:30:00"),
Expand All @@ -115,7 +115,7 @@ private static void instantiateEmployees() {
MonthDay.now(), YearMonth.now(), System.currentTimeMillis(), ZonedDateTime.now(ZoneOffset.UTC),(short)102,
1234567891L, (byte)4, 1200.0f, 68000.0, 'F',Period.of(10,10,0),
2, false, (byte) 2, 'F', (short) 30, 60000L,
4.0f, 6000.0));
4.0f, 6000.0, java.util.Date.from(Instant.now())));

employees.add(new Employee(3, new BigDecimal("45000.99"), new BigInteger("456789123"),
"Alice", "C", "Johnson", Date.valueOf("2017-03-30"), Time.valueOf("07:45:00"),
Expand All @@ -124,7 +124,7 @@ private static void instantiateEmployees() {
false, new byte[]{5, 6}, phones3, LocalDate.now(), Instant.now(),LocalTime.now(),
MonthDay.now(), YearMonth.now(), System.currentTimeMillis(), ZonedDateTime.now(ZoneOffset.UTC),(short)104,
1234567893L, (byte)2, 950.0f, 60000.0, 'F',Period.of(10,10,0),3,
true, (byte) 3, 'M', (short) 35, 70000L, 3.5f, 7000.0));
true, (byte) 3, 'M', (short) 35, 70000L, 3.5f, 7000.0, java.util.Date.from(Instant.now())));

employees.add(new Employee(4, new BigDecimal("70000.99"), new BigInteger("654321987"),
"Bob", "D", "Williams", Date.valueOf("2018-04-15"), Time.valueOf("10:15:00"),
Expand All @@ -133,7 +133,7 @@ private static void instantiateEmployees() {
true, new byte[]{7, 8}, phones4, LocalDate.now(), Instant.now(),LocalTime.now(),
MonthDay.now(), YearMonth.now(), System.currentTimeMillis(), ZonedDateTime.now(ZoneOffset.UTC),(short)103,
1234567892L, (byte)3, 800.0f, 55000.0, 'M',Period.of(10,10,0),4,
true, (byte) 4, 'F', (short) 40, 80000L, 4.8f, 8000.0));
true, (byte) 4, 'F', (short) 40, 80000L, 4.8f, 8000.0, java.util.Date.from(Instant.now())));

employees.add(new Employee(5, new BigDecimal("55000.99"), new BigInteger("321987654"),
"Charlie", "E", "Brown", Date.valueOf("2019-05-05"), Time.valueOf("11:00:00"),
Expand All @@ -142,7 +142,7 @@ private static void instantiateEmployees() {
false, new byte[]{9, 10}, phones5, LocalDate.now(), Instant.now(),LocalTime.now(),
MonthDay.now(), YearMonth.now(), System.currentTimeMillis(), ZonedDateTime.now(ZoneOffset.UTC),(short)105,
1234567894L, (byte)5, 1400.0f, 72000.0, 'M',Period.of(10,10,0),5,
false, (byte) 5, 'M', (short) 45, 90000L, 3.8f, 9000.0));
false, (byte) 5, 'M', (short) 45, 90000L, 3.8f, 9000.0, java.util.Date.from(Instant.now())));

employees.add(new Employee(6, new BigDecimal("48000.99"), new BigInteger("159753852"),
"Eve", "F", "Davis", Date.valueOf("2020-06-10"), Time.valueOf("12:00:00"),
Expand All @@ -151,7 +151,7 @@ private static void instantiateEmployees() {
true, new byte[]{11, 12}, phones6, LocalDate.now(), Instant.now(),LocalTime.now(),
MonthDay.now(), YearMonth.now(), System.currentTimeMillis(), ZonedDateTime.now(ZoneOffset.UTC),(short)110,
1234567899L, (byte)5, 1600.0f, 80000.0, 'F',Period.of(10,10,0),6,
true, (byte) 6, 'F', (short) 50, 100000L, 4.2f, 10000.0));
true, (byte) 6, 'F', (short) 50, 100000L, 4.2f, 10000.0,java.util.Date.from(Instant.now())));

employees.add(new Employee(7, new BigDecimal("62000.99"), new BigInteger("951753852"),
"Frank", "G", "Evans", Date.valueOf("2021-07-20"), Time.valueOf("08:00:00"),
Expand All @@ -160,7 +160,7 @@ private static void instantiateEmployees() {
false, new byte[]{13, 14}, phones7, LocalDate.now(), Instant.now(),LocalTime.now(),
MonthDay.now(), YearMonth.now(), System.currentTimeMillis(), ZonedDateTime.now(ZoneOffset.UTC),(short)109,
1234567898L, (byte)2, 900.0f, 61000.0, 'M',Period.of(10,10,0),7,
false, (byte) 7, 'M', (short) 55, 110000L, 3.2f, 11000.0));
false, (byte) 7, 'M', (short) 55, 110000L, 3.2f, 11000.0,java.util.Date.from(Instant.now())));

employees.add(new Employee(8, new BigDecimal("53000.99"), new BigInteger("753951456"),
"Grace", "H", "Green", Date.valueOf("2022-08-30"), Time.valueOf("09:30:00"),
Expand All @@ -169,7 +169,7 @@ private static void instantiateEmployees() {
true, new byte[]{15, 16}, phones8, LocalDate.now(), Instant.now(),LocalTime.now(),
MonthDay.now(), YearMonth.now(), System.currentTimeMillis(), ZonedDateTime.now(ZoneOffset.UTC), (short)106,
1234567895L, (byte)1, 500.0f, 45000.0, 'F',Period.of(10,10,0),8,
true, (byte) 8, 'F', (short) 60, 120000L, 4.7f, 12000.0));
true, (byte) 8, 'F', (short) 60, 120000L, 4.7f, 12000.0,java.util.Date.from(Instant.now())));

employees.add(new Employee(9, new BigDecimal("59000.99"), new BigInteger("357159852"),
"Hank", "I", "Martinez", Date.valueOf("2023-09-01"), Time.valueOf("10:45:00"),
Expand All @@ -178,7 +178,7 @@ private static void instantiateEmployees() {
false, new byte[]{17, 18}, phones9, LocalDate.now(), Instant.now(),LocalTime.now(),
MonthDay.now(), YearMonth.now(), System.currentTimeMillis(), ZonedDateTime.now(ZoneOffset.UTC),(short)107,
1234567896L, (byte)3, 850.0f, 58000.0, 'M', Period.of(10,10,0),9,
false, (byte) 9, 'M', (short) 65, 130000L, 3.6f, 13000.0));
false, (byte) 9, 'M', (short) 65, 130000L, 3.6f, 13000.0,java.util.Date.from(Instant.now())));

employees.add(new Employee(10, new BigDecimal("61000.99"), new BigInteger("147258369"),
"Ivy", "J", "Parker", Date.valueOf("2024-09-01"), Time.valueOf("11:15:00"),
Expand All @@ -187,6 +187,6 @@ private static void instantiateEmployees() {
true, new byte[]{19, 20}, phones10, LocalDate.now(), Instant.now(),LocalTime.now(),
MonthDay.now(), YearMonth.now(), System.currentTimeMillis(), ZonedDateTime.now(ZoneOffset.UTC),(short)106,
1234567895L, (byte)1, 500.0f, 45000.0, 'F',Period.of(10,10,0),10,
true, (byte) 10, 'F', (short) 70, 140000L, 4.9f, 14000.0));
true, (byte) 10, 'F', (short) 70, 140000L, 4.9f, 14000.0,java.util.Date.from(Instant.now())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void multithreadTest2() {
try(ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray())) {
try (OracleJsonParser oParser = jsonFactory.createJsonBinaryParser(in)) {
Organisation deserOrg = (Organisation) conv.deserialize(oParser, Organisation.class);
Assertions.assertEquals(deserOrg, organisation);
Assertions.assertEquals(organisation, deserOrg);
}
}

Expand Down
Loading