Skip to content

Package: YearMonthTypeSerializer

YearMonthTypeSerializer

nameinstructionbranchcomplexitylinemethod
YearMonthTypeSerializer(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(YearMonth, 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%
static {...}
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(YearMonth)
M: 7 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.YearMonth;
17: import java.time.format.DateTimeFormatter;
18: import java.util.Locale;
19:
20: /**
21: * Serializer of the {@link YearMonth} type.
22: */
23: class YearMonthTypeSerializer extends AbstractDateSerializer<YearMonth> {
24:
25: private static final DateTimeFormatter DEFAULT_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM").withZone(UTC);
26:
27: YearMonthTypeSerializer(TypeSerializerBuilder serializerBuilder) {
28: super(serializerBuilder);
29: }
30:
31: @Override
32: protected Instant toInstant(YearMonth value) {
33: return value.atDay(1).atStartOfDay(UTC).toInstant();
34: }
35:
36: @Override
37: protected String formatDefault(YearMonth value, Locale locale) {
38: return DEFAULT_FORMAT.withLocale(locale).format(value);
39: }
40:
41: }