Skip to content

Package: SerializerUtils

SerializerUtils

nameinstructionbranchcomplexitylinemethod
SerializerUtils()
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
createTypedTermDefinition(String, String, String)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
createdTypedValueNode(String, String, String)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
isAnnotationReference(Object, SerializationContext)
M: 0 C: 15
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: package cz.cvut.kbss.jsonld.serialization.serializer;
2:
3: import cz.cvut.kbss.jsonld.JsonLd;
4: import cz.cvut.kbss.jsonld.common.BeanAnnotationProcessor;
5: import cz.cvut.kbss.jsonld.common.BeanClassProcessor;
6: import cz.cvut.kbss.jsonld.serialization.JsonNodeFactory;
7: import cz.cvut.kbss.jsonld.serialization.model.JsonNode;
8: import cz.cvut.kbss.jsonld.serialization.model.ObjectNode;
9: import cz.cvut.kbss.jsonld.serialization.traversal.SerializationContext;
10:
11: /**
12: * Utilities for serializers.
13: */
14: public class SerializerUtils {
15:
16: private SerializerUtils() {
17: throw new AssertionError("No instances for you!");
18: }
19:
20: /**
21: * Checks whether the specified value in the specified context is an annotation property value referencing an
22: * individual (resource).
23: *
24: * @param value Value to examine
25: * @param ctx Serialization context
26: * @return {@code true} if the value is an annotation property value reference, {@code false} otherwise
27: */
28: public static boolean isAnnotationReference(Object value, SerializationContext<?> ctx) {
29:• return BeanAnnotationProcessor.isAnnotationProperty(ctx.getField()) && BeanClassProcessor.isIdentifierType(
30: value.getClass()) && !(value instanceof String);
31: }
32:
33: /**
34: * Creates a term definition node containing identifier and type attributes.
35: * @param term Term whose definition to create
36: * @param id Mapped term identifier (IRI)
37: * @param type Type of the mapped term
38: * @return Term definition node
39: */
40: public static ObjectNode createTypedTermDefinition(String term, String id, String type) {
41: final ObjectNode termDef = JsonNodeFactory.createObjectNode(term);
42: termDef.addItem(JsonNodeFactory.createLiteralNode(JsonLd.ID, id));
43: termDef.addItem(JsonNodeFactory.createLiteralNode(JsonLd.TYPE, type));
44: return termDef;
45: }
46:
47: /**
48: * Serializes the specified value as a JSON object with value ({@link JsonLd#VALUE}) and type ({@link
49: * JsonLd#TYPE}).
50: *
51: * @param term Term to identify the object in the enclosing object
52: * @param value Value to serialize
53: * @param type Value type to use
54: * @return Resulting JSON node
55: */
56: public static JsonNode createdTypedValueNode(String term, String value, String type) {
57: final ObjectNode node = JsonNodeFactory.createObjectNode(term);
58: node.addItem(JsonNodeFactory.createLiteralNode(JsonLd.TYPE, type));
59: node.addItem(JsonNodeFactory.createLiteralNode(JsonLd.VALUE, value));
60: return node;
61: }
62: }