Skip to contentPackage: ValueSerializers
ValueSerializers
Coverage
1: /**
2: * Copyright (C) 2022 Czech Technical University in Prague
3: * <p>
4: * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
5: * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
6: * version.
7: * <p>
8: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10: * details. You should have received a copy of the GNU General Public License along with this program. If not, see
11: * <http://www.gnu.org/licenses/>.
12: */
13: package cz.cvut.kbss.jsonld.serialization.serializer;
14:
15: import cz.cvut.kbss.jsonld.common.Configurable;
16: import cz.cvut.kbss.jsonld.serialization.traversal.SerializationContext;
17:
18: import java.util.Optional;
19: import java.util.Set;
20:
21: /**
22: * Provides serializers for JSON-LD tree building.
23: */
24: public interface ValueSerializers extends Configurable {
25:
26: /**
27: * Checks whether a custom serializer is registered for the specified type.
28: *
29: * @param type Type to check for custom serializer for
30: * @param <T> Type of value
31: * @return Whether a custom serializer exists
32: */
33: <T> boolean hasCustomSerializer(Class<T> type);
34:
35: /**
36: * Gets a custom serializer for the specified serialization context.
37: *
38: * @param ctx Context representing the value to serialize
39: * @param <T> Type of the value
40: * @return Optional containing the custom serializer registered for the specified value or an empty optional if there is no custom
41: * serializer registered
42: * @see #getOrDefault(SerializationContext)
43: */
44: <T> Optional<ValueSerializer<T>> getSerializer(SerializationContext<T> ctx);
45:
46: /**
47: * Gets a custom serializer registered for the specified serialization context or a default serializer if there is no custom one registered.
48: *
49: * @param ctx Context representing the value to serialize
50: * @param <T> Type of the value
51: * @return Value serializer for the specified context
52: * @see #getSerializer(SerializationContext)
53: */
54: <T> ValueSerializer<T> getOrDefault(SerializationContext<T> ctx);
55:
56: /**
57: * Registers the specified serializer for the specified type.
58: *
59: * @param forType Type to be serialized using the specified serializer
60: * @param serializer Serializer to register
61: * @param <T> Value type
62: */
63: <T> void registerSerializer(Class<T> forType, ValueSerializer<? super T> serializer);
64:
65: ValueSerializer<String> getIdentifierSerializer();
66:
67: void registerIdentifierSerializer(ValueSerializer<String> idSerializer);
68:
69: ValueSerializer<Set<String>> getTypesSerializer();
70:
71: void registerTypesSerializer(ValueSerializer<Set<String>> typesSerializer);
72: }