Skip to content

Package: InstantSerializer

InstantSerializer

nameinstructionbranchcomplexitylinemethod
InstantSerializer(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(Instant, 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(Instant)
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%
formatWithFormatter(Instant, 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(Instant)
M: 2 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.util.Locale;
18:
19: import org.eclipse.yasson.internal.JsonbDateFormatter;
20:
21: /**
22: * Serializer of the {@link Instant} type.
23: */
24: class InstantSerializer extends AbstractDateSerializer<Instant> {
25:
26: InstantSerializer(TypeSerializerBuilder serializerBuilder) {
27: super(serializerBuilder);
28: }
29:
30: @Override
31: protected Instant toInstant(Instant value) {
32: return value;
33: }
34:
35: @Override
36: protected String formatDefault(Instant value, Locale locale) {
37: return DateTimeFormatter.ISO_INSTANT.withLocale(locale).format(value);
38: }
39:
40: @Override
41: protected String formatWithFormatter(Instant value, DateTimeFormatter formatter) {
42: return formatter.withZone(UTC).format(value);
43: }
44:
45: @Override
46: protected String formatStrictIJson(Instant value) {
47: return JsonbDateFormatter.IJSON_DATE_FORMATTER.withZone(UTC).format(value);
48: }
49: }