Skip to content

Commit 462d72a

Browse files
committed
Fixed List and Map serializers
1 parent 7622502 commit 462d72a

File tree

4 files changed

+33
-21
lines changed

4 files changed

+33
-21
lines changed

README.MD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ maven {
1717
url = 'https://repo.mikigal.pl/releases'
1818
}
1919
20-
compile group: 'pl.mikigal', name: 'ConfigAPI', version: '1.0'
20+
compile group: 'pl.mikigal', name: 'ConfigAPI', version: '1.0.1'
2121
```
2222

2323
#### Maven
@@ -30,7 +30,7 @@ compile group: 'pl.mikigal', name: 'ConfigAPI', version: '1.0'
3030
<dependency>
3131
<groupId>pl.mikigal</groupId>
3232
<artifactId>ConfigAPI</artifactId>
33-
<version>1.0</version>
33+
<version>1.0.1</version>
3434
<scope>compile</scope>
3535
</dependency>
3636
```

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group 'pl.mikigal'
7-
version '1.0'
7+
version '1.0.1'
88

99
publishing {
1010
repositories {

src/main/java/pl/mikigal/config/serializer/universal/UniversalListSerializer.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ public class UniversalListSerializer extends Serializer<List> {
1717
protected void saveObject(String path, List object, BukkitConfiguration configuration) {
1818
Class<?> generic = TypeUtils.getListGeneric(object);
1919
Serializer<?> serializer = Serializers.of(generic);
20-
if (serializer == null) {
20+
if (serializer == null && !TypeUtils.isSimpleType(generic)) {
2121
throw new MissingSerializerException(generic);
2222
}
2323

2424
configuration.set(path + ".type", generic.getName());
2525
for (int i = 0; i < object.size(); i++) {
26+
if (serializer == null) {
27+
configuration.set(path + "." + i, object.get(i));
28+
continue;
29+
}
30+
2631
serializer.serialize(path + "." + i, object.get(i), configuration);
2732
}
2833
}
@@ -41,12 +46,12 @@ public List<?> deserialize(String path, BukkitConfiguration configuration) {
4146

4247
Serializer<?> serializer = Serializers.of(serializerClass);
4348

44-
if (serializer == null) {
45-
try {
49+
try {
50+
if (serializer == null && !TypeUtils.isSimpleType(Class.forName(serializerClass))) {
4651
throw new MissingSerializerException(Class.forName(serializerClass));
47-
} catch (ClassNotFoundException e) {
48-
throw new MissingSerializerException("Could not find class " + serializerClass);
4952
}
53+
} catch (ClassNotFoundException e) {
54+
throw new MissingSerializerException("Could not find class " + serializerClass);
5055
}
5156

5257
List list = new ArrayList<>();
@@ -55,6 +60,11 @@ public List<?> deserialize(String path, BukkitConfiguration configuration) {
5560
continue;
5661
}
5762

63+
if (serializer == null) {
64+
list.add(configuration.get(path + "." + index));
65+
continue;
66+
}
67+
5868
list.add(serializer.deserialize(path + "." + index, configuration));
5969
}
6070

src/main/java/pl/mikigal/config/serializer/universal/UniversalMapSerializer.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,18 @@ public class UniversalMapSerializer extends Serializer<Map> {
1616
@Override
1717
protected void saveObject(String path, Map object, BukkitConfiguration configuration) {
1818
Class<?> generic = TypeUtils.getMapGeneric(object)[1];
19-
if (TypeUtils.isSimpleType(generic)) {
20-
for (Map.Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) {
21-
configuration.set(path + "." + entry.getKey(), entry.getValue());
22-
}
23-
24-
return;
25-
}
26-
2719
Serializer<?> serializer = Serializers.of(generic);
28-
if (serializer == null) {
20+
if (serializer == null && !TypeUtils.isSimpleType(generic)) {
2921
throw new MissingSerializerException(generic);
3022
}
3123

3224
configuration.set(path + ".type", generic.getName());
3325
for (Map.Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) {
26+
if (serializer == null) {
27+
configuration.set(path + "." + entry.getKey(), entry.getValue());
28+
continue;
29+
}
30+
3431
serializer.serialize(path + "." + entry.getKey(), entry.getValue(), configuration);
3532
}
3633
}
@@ -58,12 +55,12 @@ protected void saveObject(String path, Map object, BukkitConfiguration configura
5855

5956
Serializer<?> serializer = Serializers.of(serializerClass);
6057

61-
if (serializer == null) {
62-
try {
58+
try {
59+
if (serializer == null && !TypeUtils.isSimpleType(Class.forName(serializerClass))) {
6360
throw new MissingSerializerException(Class.forName(serializerClass));
64-
} catch (ClassNotFoundException e) {
65-
throw new MissingSerializerException("Could not find class " + serializerClass);
6661
}
62+
} catch (ClassNotFoundException e) {
63+
throw new MissingSerializerException("Could not find class " + serializerClass);
6764
}
6865

6966
Map map = new HashMap<>();
@@ -72,6 +69,11 @@ protected void saveObject(String path, Map object, BukkitConfiguration configura
7269
continue;
7370
}
7471

72+
if (serializer == null) {
73+
map.put(key, configuration.get(path + "." + key));
74+
continue;
75+
}
76+
7577
map.put(key, serializer.deserialize(path + "." + key, configuration));
7678
}
7779

0 commit comments

Comments
 (0)