Skip to content

Package: Deserializer

Deserializer

nameinstructionbranchcomplexitylinemethod
Deserializer(InstanceBuilder, DeserializerConfig)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
configuration()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getObjectTypes(JsonObject)
M: 4 C: 23
85%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 5
100%
M: 0 C: 1
100%
resolveTargetClass(JsonObject, Class)
M: 0 C: 16
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * JB4JSON-LD
3: * Copyright (C) 2023 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jsonld.deserialization.expanded;
19:
20: import cz.cvut.kbss.jsonld.Configuration;
21: import cz.cvut.kbss.jsonld.JsonLd;
22: import cz.cvut.kbss.jsonld.common.BeanClassProcessor;
23: import cz.cvut.kbss.jsonld.deserialization.InstanceBuilder;
24: import cz.cvut.kbss.jsonld.deserialization.util.ValueUtils;
25: import jakarta.json.JsonObject;
26: import jakarta.json.JsonValue;
27:
28: import java.util.Collections;
29: import java.util.List;
30: import java.util.stream.Collectors;
31:
32: abstract class Deserializer<X> {
33:
34: final InstanceBuilder instanceBuilder;
35: final DeserializerConfig config;
36:
37: Deserializer(InstanceBuilder instanceBuilder, DeserializerConfig config) {
38: this.instanceBuilder = instanceBuilder;
39: this.config = config;
40: }
41:
42: Configuration configuration() {
43: return config.getConfiguration();
44: }
45:
46: <T> Class<? extends T> resolveTargetClass(JsonObject jsonRoot, Class<T> resultClass) {
47:• if (BeanClassProcessor.isIdentifierType(resultClass)) {
48: return resultClass;
49: }
50: final List<String> types = getObjectTypes(jsonRoot);
51: return config.getTargetResolver().getTargetClass(resultClass, types);
52: }
53:
54: List<String> getObjectTypes(JsonObject jsonLdObject) {
55: final JsonValue types = jsonLdObject.get(JsonLd.TYPE);
56:• if (types == null) {
57: return Collections.emptyList();
58: }
59:• assert types.getValueType() == JsonValue.ValueType.ARRAY;
60: return types.asJsonArray().stream().map(ValueUtils::stringValue).collect(Collectors.toList());
61: }
62:
63: abstract void processValue(X value);
64: }