Skip to content

Commit 69af2e6

Browse files
...
1 parent ef49dcd commit 69af2e6

File tree

8 files changed

+27
-20
lines changed

8 files changed

+27
-20
lines changed

SerialX-core/src/main/java/org/ugp/serialx/Serializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
/**
3838
* {@link org.ugp.serialx.Serializer} is powerful utility class that allows you to serialize any object in Java using custom data format compiled by recursive descent parser consisting of {@link DataParser}s.
39-
* This class itself is responsible for utility, formating and managing input-output (IO) of content obtained from parsers and protocols as well as their management of their usage!
39+
* This class itself is responsible for formating and managing input-output (IO) of content obtained from parsers and protocols as well as their management of their usage!
4040
* It is instance of {@link Scope} so we can say that this is scope that can serialize itself using system of already mentioned {@link DataParser} and {@link SerializationProtocol}!
4141
*
4242
* @author PETO

SerialX-core/src/main/java/org/ugp/serialx/converters/DataParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import org.ugp.serialx.Scope;
88

99
/**
10-
* This class supposed to be used to parse strings back to java objects using {@link DataParser#parse(String, Object...)}!
10+
* This interface is supposed to be used to parse strings back to java objects using {@link DataParser#parse(String, Object...)}!
1111
* Instance of DataParser should be registered into {@link DataParser#REGISTRY} or other external registry in order to work, also only one instance of each DataParser should be used and accessed via this registry! <br>
1212
* Static method {@link DataParser#parseObj} is used to walk this registry and parse inserted string in process, in other words we can say that this interface contains <a href = "https://en.wikipedia.org/wiki/Recursive_descent_parser">recursive descent parse</a> that uses its own implementations!
1313
*

SerialX-core/src/main/java/org/ugp/serialx/protocols/EnumProtocol.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package org.ugp.serialx.protocols;
22

3-
import java.util.Collection;
4-
53
/**
6-
* EnumProtocol is universal protocol to serialize any enumerator ({@link Collection} instance).
4+
* EnumProtocol is universal protocol to serialize any enumerator ({@link Enum} instance).
75
*
86
* @author PETO
97
*

SerialX-core/src/main/java/org/ugp/serialx/protocols/SerializationProtocol.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public abstract class SerializationProtocol<T>
3030
*
3131
* @since 1.3.0
3232
*/
33-
public static final ProtocolRegistry REGISTRY = new ProtocolRegistry(/*This might be unsafe: new UniversalObjectInstantiationProtocol<>(Object.class),*/ new ListProtocol(), new MapProtocol(), new StringProtocol(), new ScopeProtocol(), new SelfSerializableProtocol(), new EnumProtocol());
33+
public static final ProtocolRegistry REGISTRY = new ProtocolRegistry(/*This might be unsafe: new UniversalObjectInstantiationProtocol<>(Object.class), new SelfSerializableProtocol(SelfSerializable.class),*/ new ListProtocol(), new MapProtocol(), new StringProtocol(), new ScopeProtocol(), new EnumProtocol());
3434

3535
/**
3636
* This mode is for protocols that are used for serialization only!

SerialX-juss/src/main/java/org/ugp/serialx/juss/protocols/AutoProtocol.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
package org.ugp.serialx.protocols;
1+
package org.ugp.serialx.juss.protocols;
2+
3+
import static org.ugp.serialx.Utils.Instantiate;
24

35
import java.beans.IntrospectionException;
46
import java.beans.PropertyDescriptor;
@@ -8,7 +10,7 @@
810

911
import org.ugp.serialx.Scope;
1012
import org.ugp.serialx.Serializer;
11-
import org.ugp.serialx.Utils;
13+
import org.ugp.serialx.protocols.SerializationProtocol;
1214

1315
/**
1416
* This is automatic protocol that will automatically serialize every or selected field in object that has valid and public getter and setter!
@@ -128,7 +130,7 @@ public AutoProtocol(Class<T> applicableFor, boolean useScope, List<PropertyDescr
128130
*/
129131
public T createBlankInstance(Class<? extends T> objectClass) throws Exception
130132
{
131-
return Utils.Instantiate(objectClass);
133+
return Instantiate(objectClass);
132134
}
133135

134136
@Override

SerialX-juss/src/main/java/org/ugp/serialx/juss/protocols/SelfSerializable.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
package org.ugp.serialx.protocols;
2-
3-
import java.io.Serializable;
1+
package org.ugp.serialx.juss.protocols;
42

53
/**
6-
* This is based on pretty similar concept as regular {@link Serializable} is! However this interface is meant to create its instance programmatically via constructor!
4+
* This is based on pretty similar concept as regular {@link java.io.Serializable} is! However this interface is meant to create its instance programmatically via constructor!
75
* So condition of using this is that array of objects returned by {@link SelfSerializable#serialize()} must be applicable for some public constructor of certain class implementing this!
86
* Specific instances of this interface will be created by calling that public constructor! This is done reflectively by {@link SelfSerializableProtocol}!
97
*

SerialX-juss/src/main/java/org/ugp/serialx/juss/protocols/SelfSerializableProtocol.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.ugp.serialx.protocols;
1+
package org.ugp.serialx.juss.protocols;
22

33
/**
44
* SelfSerializableProtocol is universal protocol to serialize any {@link SelfSerializable} instance. The condition of use is implementation of {@link SelfSerializable} interface and public constructor that can be called with content returned by specific {@link SelfSerializable#serialize()}!
@@ -11,13 +11,19 @@
1111
*/
1212
public class SelfSerializableProtocol extends UniversalObjectInstantiationProtocol<SelfSerializable>
1313
{
14-
public SelfSerializableProtocol()
14+
/**
15+
* @param applicableFor | Class implementing {@link SelfSerializable} that can be serialized using this protocol.<br>
16+
* Note: Passing {@link SelfSerializable#getClass()} will make this protocol universal and work for any {@link SelfSerializable} instance, this can be considered unsafe in some cases...
17+
*
18+
* @since 1.3.7
19+
*/
20+
public SelfSerializableProtocol(Class<? extends SelfSerializable> applicableFor)
1521
{
16-
super(SelfSerializable.class);
22+
super(applicableFor);
1723
}
1824

1925
@Override
20-
public Object[] serialize(SelfSerializable object)
26+
public Object[] serialize(SelfSerializable object)
2127
{
2228
return object.serialize();
2329
}
@@ -28,3 +34,4 @@ public byte getMode()
2834
return MODE_ALL;
2935
}
3036
}
37+

SerialX-juss/src/main/java/org/ugp/serialx/juss/protocols/UniversalObjectInstantiationProtocol.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
package org.ugp.serialx.protocols;
1+
package org.ugp.serialx.juss.protocols;
22

33
import java.lang.reflect.Constructor;
44
import java.util.Arrays;
55

66
import org.ugp.serialx.LogProvider;
77
import org.ugp.serialx.Utils;
8+
import org.ugp.serialx.protocols.SerializationProtocol;
89

910
/**
1011
* Universal protocol for deserializing any object using its constructor. Args array of {@link UniversalObjectInstantiationProtocol#unserialize(Class, Object...)} must have elements applicable as arguments for some constructor of required objects class!
@@ -18,14 +19,15 @@
1819
*/
1920
public class UniversalObjectInstantiationProtocol<T> extends SerializationProtocol<T> {
2021

21-
protected final Class<T> applicableFor;
22+
protected final Class<? extends T> applicableFor;
2223

2324
/**
2425
* @param applicableFor | Class that can be serialized using this protocol.
26+
* Note: Passing {@link Object#getClass()} will make this protocol universal and work for any {@link Object} instance, this can be considered unsafe in some cases...
2527
*
2628
* @since 1.3.7
2729
*/
28-
public UniversalObjectInstantiationProtocol(Class<T> applicableFor)
30+
public UniversalObjectInstantiationProtocol(Class<? extends T> applicableFor)
2931
{
3032
this.applicableFor = applicableFor;
3133
}

0 commit comments

Comments
 (0)