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