Skip to content

Package: LocalDateTimeSerializer

LocalDateTimeSerializer

nameinstructionbranchcomplexitylinemethod
LocalDateTimeSerializer(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(LocalDateTime, Locale)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
formatStrictIJson(LocalDateTime)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
formatWithFormatter(LocalDateTime, DateTimeFormatter)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
toInstant(LocalDateTime)
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%

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.LocalDateTime;
17: import java.time.ZonedDateTime;
18: import java.time.format.DateTimeFormatter;
19: import java.util.Locale;
20:
21: import org.eclipse.yasson.internal.JsonbDateFormatter;
22:
23: /**
24: * Serializer of the {@link LocalDateTime} type.
25: */
26: class LocalDateTimeSerializer extends AbstractDateSerializer<LocalDateTime> {
27:
28: LocalDateTimeSerializer(TypeSerializerBuilder builder) {
29: super(builder);
30: }
31:
32: @Override
33: protected Instant toInstant(LocalDateTime value) {
34: return value.atZone(UTC).toInstant();
35: }
36:
37: @Override
38: protected String formatDefault(LocalDateTime value, Locale locale) {
39: return DateTimeFormatter.ISO_LOCAL_DATE_TIME.withLocale(locale).format(value);
40: }
41:
42: @Override
43: protected String formatWithFormatter(LocalDateTime value, DateTimeFormatter formatter) {
44: return getZonedFormatter(formatter).format(value);
45: }
46:
47: @Override
48: protected String formatStrictIJson(LocalDateTime value) {
49: final ZonedDateTime zonedDateTime = value.atZone(UTC);
50: return JsonbDateFormatter.IJSON_DATE_FORMATTER.format(zonedDateTime);
51: }
52:
53: }