Skip to content

Commit bfe1ac6

Browse files
committed
Fix serialization/deserialization issue
1 parent 7005b9d commit bfe1ac6

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

src/main/java/simplexity/simplepronouns/Pronoun.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
public final class Pronoun {
66

7-
private final String subjective;
8-
private final String objective;
9-
private final String possessive;
10-
private final String possessiveAdjective;
11-
private final String reflexive;
7+
private String subjective = "";
8+
private String objective = "";
9+
private String possessive = "";
10+
private String possessiveAdjective = "";
11+
private String reflexive = "";
1212

1313
public Pronoun(String subjective, String objective, String possessive, String possessiveAdjective,
1414
String reflexive) {
@@ -30,15 +30,18 @@ public String toString() {
3030
}
3131

3232
public static String serialize(@NotNull Pronoun pronoun) {
33-
return String.format("%s///%s///%s///%s///%s",
34-
pronoun.subjective, pronoun.objective, pronoun.possessive,
35-
pronoun.possessiveAdjective, pronoun.reflexive);
33+
return String.join("///",
34+
pronoun.subjective.isEmpty() ? " " : pronoun.subjective,
35+
pronoun.objective.isEmpty() ? " " : pronoun.objective,
36+
pronoun.possessive.isEmpty() ? " " : pronoun.possessive,
37+
pronoun.possessiveAdjective.isEmpty() ? " " : pronoun.possessiveAdjective,
38+
pronoun.reflexive.isEmpty() ? " " : pronoun.reflexive);
3639
}
3740

3841
public static Pronoun deserialize(@NotNull String string) {
39-
String[] arr = string.split("///");
42+
String[] arr = string.split("///", -1); // Ensure split keeps empty fields
4043
if (arr.length != 5) return null;
41-
return new Pronoun(arr[0], arr[1], arr[2], arr[3], arr[4]);
44+
return new Pronoun(arr[0].trim(), arr[1].trim(), arr[2].trim(), arr[3].trim(), arr[4].trim());
4245
}
4346

4447
public String getObjective() {

src/main/java/simplexity/simplepronouns/configs/PronounLoader.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ public void loadPronouns() {
5656
ConfigurationSection configSection = pronounConfig.getConfigurationSection("pronouns." + pronounKey);
5757
if (configSection == null) continue;
5858
pronouns.put(pronounKey, new Pronoun(
59-
configSection.getString("subjective"),
60-
configSection.getString("objective"),
61-
configSection.getString("possessive"),
62-
configSection.getString("possessive-adj"),
63-
configSection.getString("reflexive")));
59+
configSection.getString("subjective", ""),
60+
configSection.getString("objective", ""),
61+
configSection.getString("possessive", ""),
62+
configSection.getString("possessive-adj", ""),
63+
configSection.getString("reflexive", "")));
6464
}
6565
}
6666

0 commit comments

Comments
 (0)