You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (objinstanceofCharSequence && indexOfNotInObj((CharSequence) obj, '\n', '\r') != -1)
246
246
return"Multiline char sequence!";
247
-
returnnewStringBuilder("Object of ").append(obj.getClass().getName()).append(": \"").append(obj.toString()).append("\" serialized using ").append(getProtocolFor(obj, SerializationProtocol.MODE_ALL, argsUsedConvert).toString()).append("!");
247
+
returnnewStringBuilder("Object of ").append(obj.getClass().getName()).append(": \"").append(obj.toString()).append("\" serialized using ").append(getProtocolFor(obj, SerializationProtocol.MODE_SERIALIZE_DESERIALIZE | getProtocolType(), argsUsedConvert)).append("!");
248
248
}
249
249
250
250
/**
@@ -276,6 +276,26 @@ public void setUseBase64IfCan(boolean useBase64IfCan)
276
276
{
277
277
this.useBase64IfCan = useBase64IfCan;
278
278
}
279
+
280
+
/**
281
+
* @return The additional protocol type that will chained with {@link SerializationProtocol#MODE_SERIALIZE} and {@link SerializationProtocol#MODE_DESERIALIZE} (none (0) by default).
282
+
*
283
+
* @since 1.3.8
284
+
*/
285
+
publiclonggetProtocolType()
286
+
{
287
+
returnprotocolType;
288
+
}
289
+
290
+
/**
291
+
* @param protocolType | Value of additional protocol type that will chained with {@link SerializationProtocol#MODE_SERIALIZE} and {@link SerializationProtocol#MODE_DESERIALIZE} (none (0) by default).
292
+
*
293
+
* @since 1.3.8
294
+
*/
295
+
publicvoidsetProtocolType(longprotocolType)
296
+
{
297
+
this.protocolType = protocolType;
298
+
}
279
299
280
300
/**
281
301
* @return Classes that are eligible for public static member invocation (:: operator)!<br>
@@ -298,7 +318,7 @@ public Set<Class<?>> getInvokableClasses()
Copy file name to clipboardExpand all lines: SerialX-core/src/main/java/org/ugp/serialx/protocols/SerializationProtocol.java
+40-42Lines changed: 40 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ public abstract class SerializationProtocol<T>
26
26
/**
27
27
* This is serialization protocol registry. This is place where your {@link SerializationProtocol} implementations should be registered in order to work properly! Do not add there two protocols applicable for exactly same classes!
28
28
* Also I recommend to register protocols in generic order of object that are they applicable for! In other words If some object Foo has child classes, protocol of these classes should be registered after each other.
29
-
* Defaultly there are registered protocols from ugp.org.SerialX.protocols.
29
+
* Defaultly there are registered protocols from org.ugp.serialx.protocols.
30
30
*
31
31
* @since 1.3.0
32
32
*/
@@ -37,30 +37,30 @@ public abstract class SerializationProtocol<T>
37
37
*
38
38
* @since 1.3.5
39
39
*/
40
-
publicstaticfinalbyteMODE_SERIALIZE = 0;
40
+
publicstaticfinallongMODE_SERIALIZE = 0b01;
41
41
42
42
/**
43
43
* This mode is for protocols that are used for deserialization only!
44
44
*
45
45
* @since 1.3.5
46
46
*/
47
-
publicstaticfinalbyteMODE_DESERIALIZE = 1;
47
+
publicstaticfinallongMODE_DESERIALIZE = 0b10;
48
48
49
49
/**
50
-
* This mode is for protocols that chat can both serialize and deserialize!
50
+
* This mode is for protocols that chat can both serialize and deserialize (<code>MODE_SERIALIZE | MODE_DESERIALIZE</code>)!
@@ -128,17 +128,16 @@ public T unserialize(Class<? extends T> objectClass, Scope scope) throws Excepti
128
128
publicabstractClass<? extendsT> applicableFor();
129
129
130
130
/**
131
-
* @return Mode of this protocol. Default is {@link SerializationProtocol#MODE_ALL}!
131
+
* @return Mode of this protocol, describing its type or operation mode. Can be one or more chained with binary or. Default is {@link SerializationProtocol#MODE_SERIALIZE_DESERIALIZE}!
132
132
*
133
-
* @see SerializationProtocol#MODE_ALL
134
133
* @see SerializationProtocol#MODE_DESERIALIZE
135
134
* @see SerializationProtocol#MODE_SERIALIZE
136
135
*
137
136
* @since 1.3.5
138
137
*/
139
-
publicbytegetMode()
138
+
publiclonggetMode()
140
139
{
141
-
returnMODE_ALL;
140
+
returnMODE_SERIALIZE_DESERIALIZE;
142
141
}
143
142
144
143
/**
@@ -174,21 +173,22 @@ public void setActive(boolean isActive)
* @param aditionalType | Additional protocol mode that will be chained together with {@link SerializationProtocol#MODE_DESERIALIZE}.
182
182
* @param object | The object.
183
183
*
184
184
* @return Array of objects to serialize created from given object. Object will be serialized via protocol picked from registry.
185
185
* {@link SerializationProtocol#serialize(Class, Object...)} method of picked protocol will be called! Null will be returned if no protocol was found and you will be prompted with error message!
LogProvider.instance.logErr("Unable to serialize \"" + object + "\" because there is no registered and active protocol for serializing " + object.getClass() + "!", null);
@@ -210,11 +210,12 @@ public static <O> Object[] serializeObj(ProtocolRegistry registry, O object) thr
* @param aditionalType | Additional protocol mode that will be chained together with {@link SerializationProtocol#MODE_DESERIALIZE}.
218
219
* @param objectClass | The class of object that should be created. This can be useful when object {@link O} has children classes with same constructors. You can use reflection to make protocol working also for these child classes! This class is also used to pick suitable protocol!
LogProvider.instance.logErr("Unable to unserialize " + Arrays.toString(args) + " because there is no registered and active protocol for unserializing \"" + objectClass + "\"!", null);
@@ -302,68 +303,65 @@ public void add(int index, SerializationProtocol<?> element)
302
303
/**
303
304
* @param protocolsClass | Protocols class.
304
305
*
305
-
* @return Protocol by its class.
306
+
* @return Protocol by its class. Pretty much equivalent with {@link Registry#get(Class)}.
returnnewStringBuilder("Object of ").append(obj.getClass().getName()).append(": \"").append(obj.toString()).append("\" serialized using ").append(getProtocolFor(obj, SerializationProtocol.MODE_ALL, argsUsedConvert).toString()).append("!");
0 commit comments