Skip to content

Package: OptionalIntSerializer

OptionalIntSerializer

nameinstructionbranchcomplexitylinemethod
OptionalIntSerializer(ModelSerializer)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
serialize(Object, JsonGenerator, SerializationContextImpl)
M: 24 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 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.util.OptionalInt;
16:
17: import jakarta.json.stream.JsonGenerator;
18:
19: import org.eclipse.yasson.internal.SerializationContextImpl;
20: import org.eclipse.yasson.internal.serializer.ModelSerializer;
21:
22: /**
23: * Serializer of the {@link OptionalInt} type.
24: */
25: class OptionalIntSerializer implements ModelSerializer {
26:
27: private final ModelSerializer typeSerializer;
28:
29: OptionalIntSerializer(ModelSerializer typeSerializer) {
30: this.typeSerializer = typeSerializer;
31: }
32:
33: @Override
34: public void serialize(Object value, JsonGenerator generator, SerializationContextImpl context) {
35: OptionalInt optionalInt = (OptionalInt) value;
36:• if (optionalInt != null && optionalInt.isPresent()) {
37: typeSerializer.serialize(optionalInt.getAsInt(), generator, context);
38: } else {
39: typeSerializer.serialize(null, generator, context);
40: }
41: }
42: }