Skip to content

Commit

Permalink
Support for Java 8 Date/Time API in parameters #125
Browse files Browse the repository at this point in the history
add support java.sql.Time
  • Loading branch information
plakhov committed Mar 3, 2021
1 parent fcec1a2 commit 52a0dd5
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public Object toObject(Type type, String value, @Nullable String modelVersion) t
if (OffsetTime.class == clazz) {
return Datatypes.getNN(OffsetTime.class).parse(value);
}
if (Time.class == clazz) {
return Datatypes.getNN(Time.class).parse(value);
}
if (BigDecimal.class == clazz) return Datatypes.getNN(BigDecimal.class).parse(value);
if (Boolean.class == clazz || Boolean.TYPE == clazz) return Datatypes.getNN(Boolean.class).parse(value);
if (Long.class == clazz || Long.TYPE == clazz) return Datatypes.getNN(Long.class).parse(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.inject.Inject;
import javax.validation.constraints.Pattern;
import java.math.BigDecimal;
import java.sql.Time;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
Expand Down Expand Up @@ -55,12 +56,13 @@ public Integer sum(int number1, String number2) {
}

@Override
public String convertDate(LocalDate localDate, LocalDateTime localDateTime, LocalTime localTime, OffsetDateTime offsetDateTime, OffsetTime offsetTime) {
public String convertDate(LocalDate localDate, LocalDateTime localDateTime, LocalTime localTime, OffsetDateTime offsetDateTime, OffsetTime offsetTime, Time time) {
StringBuilder builder = new StringBuilder(localDate.toString()).append(",");
builder.append(localDateTime.toString()).append(",");
builder.append(localTime.toString()).append(",");
builder.append(offsetDateTime.toString()).append(",");
builder.append(offsetTime.toString());
builder.append(time.toString());
return builder.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.math.BigDecimal;
import java.sql.Time;
import java.text.ParseException;
import java.time.*;
import java.util.Date;
Expand All @@ -34,7 +35,7 @@ public interface PortalTestService {

Integer sum(int number1, String number2);

String convertDate(LocalDate localDate, LocalDateTime localDateTime, LocalTime localTime, OffsetDateTime offsetDateTime, OffsetTime offsetTime);
String convertDate(LocalDate localDate, LocalDateTime localDateTime, LocalTime localTime, OffsetDateTime offsetDateTime, OffsetTime offsetTime, Time time);

void methodWithCustomException();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<param name="localTime" type="java.time.LocalTime"/>
<param name="offsetDateTime" type="java.time.OffsetDateTime"/>
<param name="offsetTime" type="java.time.OffsetTime"/>
<param name="time" type="java.sql.Time"/>
</method>

<method name="methodWithCustomException"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"localDateTime": "2021-02-24 15:15:15.053",
"localTime": "15:15:15",
"offsetDateTime": "2021-02-24 15:15:15.053 +0400",
"offsetTime": "15:15:15 +0400"
"offsetTime": "15:15:15 +0400",
"time": "15:15:15"
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<param name="localTime" type="java.time.LocalTime"/>
<param name="offsetDateTime" type="java.time.OffsetDateTime"/>
<param name="offsetTime" type="java.time.OffsetTime"/>
<param name="time" type="java.sql.Time"/>
</method>

<method name="methodWithCustomException"/>
Expand Down

0 comments on commit 52a0dd5

Please sign in to comment.