Skip to content

Package: DateSerializer

DateSerializer

nameinstructionbranchcomplexitylinemethod
DateSerializer(TypeSerializerBuilder)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
formatDefault(Date, Locale)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
formatStrictIJson(Date)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
formatWithFormatter(Date, DateTimeFormatter)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
toInstant(Date)
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
toTemporalAccessor(Date)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0 which is available at
6: * http://www.eclipse.org/legal/epl-2.0,
7: * or the Eclipse Distribution License v. 1.0 which is available at
8: * http://www.eclipse.org/org/documents/edl-v10.php.
9: *
10: * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11: */
12:
13: package org.eclipse.yasson.internal.serializer.types;
14:
15: import java.time.Instant;
16: import java.time.format.DateTimeFormatter;
17: import java.time.temporal.TemporalAccessor;
18: import java.util.Date;
19: import java.util.Locale;
20:
21: import org.eclipse.yasson.internal.JsonbDateFormatter;
22:
23: /**
24: * Serializer of the {@link Date} type.
25: */
26: class DateSerializer<T extends Date> extends AbstractDateSerializer<T> {
27:
28: private static final DateTimeFormatter DEFAULT_DATE_FORMATTER = DateTimeFormatter.ISO_DATE_TIME.withZone(UTC);
29:
30: DateSerializer(TypeSerializerBuilder serializerBuilder) {
31: super(serializerBuilder);
32: }
33:
34: @Override
35: protected Instant toInstant(Date value) {
36: return value.toInstant();
37: }
38:
39: @Override
40: protected String formatDefault(Date value, Locale locale) {
41: return DEFAULT_DATE_FORMATTER.withLocale(locale).format(toInstant(value));
42: }
43:
44: @Override
45: protected String formatWithFormatter(Date value, DateTimeFormatter formatter) {
46: return getZonedFormatter(formatter).format(toTemporalAccessor(value));
47: }
48:
49: @Override
50: protected String formatStrictIJson(Date value) {
51: return JsonbDateFormatter.IJSON_DATE_FORMATTER.withZone(UTC).format(toTemporalAccessor(value));
52: }
53:
54: @Override
55: protected TemporalAccessor toTemporalAccessor(Date object) {
56: return toInstant(object);
57: }
58:
59: }