Skip to content

Package: ValueSerializers

ValueSerializers

Coverage

1: /*
2: * JB4JSON-LD
3: * Copyright (C) 2024 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.serialization.serializer;
19:
20: import cz.cvut.kbss.jsonld.common.Configurable;
21: import cz.cvut.kbss.jsonld.serialization.serializer.compact.IndividualSerializer;
22: import cz.cvut.kbss.jsonld.serialization.traversal.SerializationContext;
23:
24: import java.util.Optional;
25: import java.util.Set;
26:
27: /**
28: * Provides serializers for JSON-LD tree building.
29: */
30: public interface ValueSerializers extends Configurable {
31:
32: /**
33: * Checks whether a custom serializer is registered for the specified type.
34: *
35: * @param type Type to check for custom serializer for
36: * @param <T> Type of value
37: * @return Whether a custom serializer exists
38: */
39: <T> boolean hasCustomSerializer(Class<T> type);
40:
41: /**
42: * Gets a custom serializer for the specified serialization context.
43: *
44: * @param ctx Context representing the value to serialize
45: * @param <T> Type of the value
46: * @return Optional containing the custom serializer registered for the specified value or an empty optional if there is no custom
47: * serializer registered
48: * @see #getOrDefault(SerializationContext)
49: */
50: <T> Optional<ValueSerializer<T>> getSerializer(SerializationContext<T> ctx);
51:
52: /**
53: * Gets a custom serializer registered for the specified serialization context or a default serializer if there is no custom one registered.
54: *
55: * @param ctx Context representing the value to serialize
56: * @param <T> Type of the value
57: * @return Value serializer for the specified context
58: * @see #getSerializer(SerializationContext)
59: */
60: <T> ValueSerializer<T> getOrDefault(SerializationContext<T> ctx);
61:
62: /**
63: * Registers the specified serializer for the specified type.
64: *
65: * @param forType Type to be serialized using the specified serializer
66: * @param serializer Serializer to register
67: * @param <T> Value type
68: */
69: <T> void registerSerializer(Class<T> forType, ValueSerializer<? super T> serializer);
70:
71: ValueSerializer<String> getIdentifierSerializer();
72:
73: void registerIdentifierSerializer(ValueSerializer<String> idSerializer);
74:
75: ValueSerializer<Set<String>> getTypesSerializer();
76:
77: void registerTypesSerializer(ValueSerializer<Set<String>> typesSerializer);
78:
79: ValueSerializer<?> getIndividualSerializer();
80:
81: void registerIndividualSerializer(ValueSerializer<?> individualSerializer);
82: }