Skip to content

Package: ExpandedJsonLdDeserializer

ExpandedJsonLdDeserializer

nameinstructionbranchcomplexitylinemethod
ExpandedJsonLdDeserializer()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
ExpandedJsonLdDeserializer(Configuration)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
deserialize(Object, Class)
M: 13 C: 48
79%
M: 3 C: 3
50%
M: 3 C: 1
25%
M: 1 C: 9
90%
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) 2017 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.deserialization.DefaultInstanceBuilder;
19: import cz.cvut.kbss.jsonld.deserialization.InstanceBuilder;
20: import cz.cvut.kbss.jsonld.deserialization.JsonLdDeserializer;
21: import cz.cvut.kbss.jsonld.exception.JsonLdDeserializationException;
22:
23: import java.util.List;
24: import java.util.Map;
25:
26: public class ExpandedJsonLdDeserializer extends JsonLdDeserializer {
27:
28: public ExpandedJsonLdDeserializer() {
29: }
30:
31: public ExpandedJsonLdDeserializer(Configuration configuration) {
32: super(configuration);
33: }
34:
35: @Override
36: public <T> T deserialize(Object jsonLd, Class<T> resultClass) {
37:• if (!(jsonLd instanceof List)) {
38: throw new JsonLdDeserializationException(
39: "Expanded JSON-LD deserializer requires a JSON-LD array as input.");
40: }
41: final List<?> input = (List<?>) jsonLd;
42:• assert input.size() == 1;
43: final Map<?, ?> root = (Map<?, ?>) input.get(0);
44: final InstanceBuilder instanceBuilder = new DefaultInstanceBuilder(classResolver);
45: new ObjectDeserializer(instanceBuilder, new DeserializerConfig(configuration(), classResolver), resultClass)
46: .processValue(root);
47:• assert resultClass.isAssignableFrom(instanceBuilder.getCurrentRoot().getClass());
48: return resultClass.cast(instanceBuilder.getCurrentRoot());
49: }
50: }