|
16 | 16 |
|
17 | 17 | package com.fasterxml.jackson.datatype.jsr310.ser;
|
18 | 18 |
|
| 19 | +import com.fasterxml.jackson.annotation.JsonFormat; |
19 | 20 | import java.io.IOException;
|
20 | 21 | import java.time.LocalDate;
|
21 | 22 | import java.time.format.DateTimeFormatter;
|
@@ -44,28 +45,32 @@ protected LocalDateSerializer() {
|
44 | 45 | }
|
45 | 46 |
|
46 | 47 | protected LocalDateSerializer(LocalDateSerializer base,
|
47 |
| - Boolean useTimestamp, DateTimeFormatter dtf) { |
48 |
| - super(base, useTimestamp, dtf); |
| 48 | + Boolean useTimestamp, DateTimeFormatter dtf, JsonFormat.Shape shape) { |
| 49 | + super(base, useTimestamp, dtf, shape); |
49 | 50 | }
|
50 | 51 |
|
51 | 52 | public LocalDateSerializer(DateTimeFormatter formatter) {
|
52 | 53 | super(LocalDate.class, formatter);
|
53 | 54 | }
|
54 | 55 |
|
55 | 56 | @Override
|
56 |
| - protected LocalDateSerializer withFormat(Boolean useTimestamp, DateTimeFormatter dtf) { |
57 |
| - return new LocalDateSerializer(this, useTimestamp, dtf); |
| 57 | + protected LocalDateSerializer withFormat(Boolean useTimestamp, DateTimeFormatter dtf, JsonFormat.Shape shape) { |
| 58 | + return new LocalDateSerializer(this, useTimestamp, dtf, shape); |
58 | 59 | }
|
59 | 60 |
|
60 | 61 | @Override
|
61 | 62 | public void serialize(LocalDate date, JsonGenerator generator, SerializerProvider provider) throws IOException
|
62 | 63 | {
|
63 | 64 | if (useTimestamp(provider)) {
|
64 |
| - generator.writeStartArray(); |
65 |
| - generator.writeNumber(date.getYear()); |
66 |
| - generator.writeNumber(date.getMonthValue()); |
67 |
| - generator.writeNumber(date.getDayOfMonth()); |
68 |
| - generator.writeEndArray(); |
| 65 | + if (_shape == JsonFormat.Shape.NUMBER_INT) { |
| 66 | + generator.writeNumber(date.toEpochDay()); |
| 67 | + } else { |
| 68 | + generator.writeStartArray(); |
| 69 | + generator.writeNumber(date.getYear()); |
| 70 | + generator.writeNumber(date.getMonthValue()); |
| 71 | + generator.writeNumber(date.getDayOfMonth()); |
| 72 | + generator.writeEndArray(); |
| 73 | + } |
69 | 74 | } else {
|
70 | 75 | String str = (_formatter == null) ? date.toString() : date.format(_formatter);
|
71 | 76 | generator.writeString(str);
|
|
0 commit comments