Skip to content

Commit bf155b5

Browse files
committed
Upgraded to JSON 0.2.0
1 parent a683f9b commit bf155b5

25 files changed

+301
-199
lines changed

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ repositories {
2222
}
2323

2424
dependencies {
25-
implementation("com.github.jlbabilino:json:0.1.4")
25+
implementation("com.github.jlbabilino:json:0.2.0")
2626
// implementation "javax.measure:unit-api:2.1.3"
2727
// implementation "tec.units:unit-ri:1.0.3"
2828
// implementation "tech.units:indriya:2.1.3"

app/src/main/java/org/team2363/helixnavigator/document/DocumentActions.java

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.team2363.helixnavigator.ui.prompts.RobotConfigDialog;
1616
import org.team2363.helixnavigator.ui.prompts.TransformDialog;
1717

18+
import com.jlbabilino.json.InvalidJSONTranslationConfiguration;
1819
import com.jlbabilino.json.JSONArray;
1920
import com.jlbabilino.json.JSONDeserializer;
2021
import com.jlbabilino.json.JSONDeserializerException;
@@ -23,6 +24,7 @@
2324
import com.jlbabilino.json.JSONParser;
2425
import com.jlbabilino.json.JSONParserException;
2526
import com.jlbabilino.json.JSONSerializer;
27+
import com.jlbabilino.json.JSONSerializerException;
2628

2729
import javafx.beans.property.BooleanProperty;
2830
import javafx.beans.property.SimpleBooleanProperty;
@@ -304,26 +306,30 @@ public void copy() {
304306
int selectedWaypointsCount = path.getWaypointsSelectionModel().getSelectedItems().size();
305307
int selectedObstaclesCount = path.getObstaclesSelectionModel().getSelectedItems().size();
306308
int totalCount = selectedWaypointsCount + selectedObstaclesCount;
307-
if (totalCount == 0) {
308-
data = JSONSerializer.serializeString(path);
309-
} else if (totalCount == 1 && selectedWaypointsCount == 1) {
310-
data = JSONSerializer.serializeString(path.getWaypointsSelectionModel().getSelectedItem());
311-
} else if (totalCount == 1 && selectedObstaclesCount == 1) {
312-
data = JSONSerializer.serializeString(path.getObstaclesSelectionModel().getSelectedItem());
313-
} else {
314-
List<HPathElement> list = new ArrayList<>();
315-
for (HWaypoint waypoint : path.getWaypointsSelectionModel().getSelectedItems()) {
316-
list.add(waypoint);
317-
}
318-
for (HObstacle obstacle : path.getObstaclesSelectionModel().getSelectedItems()) {
319-
list.add(obstacle);
309+
try {
310+
if (totalCount == 0) {
311+
data = JSONSerializer.serializeString(path);
312+
} else if (totalCount == 1 && selectedWaypointsCount == 1) {
313+
data = JSONSerializer.serializeString(path.getWaypointsSelectionModel().getSelectedItem());
314+
} else if (totalCount == 1 && selectedObstaclesCount == 1) {
315+
data = JSONSerializer.serializeString(path.getObstaclesSelectionModel().getSelectedItem());
316+
} else {
317+
List<HPathElement> list = new ArrayList<>();
318+
for (HWaypoint waypoint : path.getWaypointsSelectionModel().getSelectedItems()) {
319+
list.add(waypoint);
320+
}
321+
for (HObstacle obstacle : path.getObstaclesSelectionModel().getSelectedItems()) {
322+
list.add(obstacle);
323+
}
324+
data = JSONSerializer.serializeString(list);
320325
}
321-
data = JSONSerializer.serializeString(list);
326+
Clipboard systemClipboard = Clipboard.getSystemClipboard();
327+
ClipboardContent content = new ClipboardContent();
328+
content.putString(data);
329+
systemClipboard.setContent(content);
330+
} catch (JSONSerializerException | InvalidJSONTranslationConfiguration e) {
331+
// TODO: log error
322332
}
323-
Clipboard systemClipboard = Clipboard.getSystemClipboard();
324-
ClipboardContent content = new ClipboardContent();
325-
content.putString(data);
326-
systemClipboard.setContent(content);
327333
}
328334
}
329335

@@ -358,7 +364,8 @@ private void paste(JSONEntry jsonEntry) {
358364
paste(entry);
359365
}
360366
}
361-
} catch (JSONDeserializerException e) {
367+
} catch (JSONDeserializerException | InvalidJSONTranslationConfiguration e) {
368+
// TODO: log error
362369
}
363370
}
364371
}

app/src/main/java/org/team2363/helixnavigator/document/DocumentManager.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
import java.util.Optional;
66
import java.util.logging.Logger;
77

8+
import com.jlbabilino.json.InvalidJSONTranslationConfiguration;
89
import com.jlbabilino.json.JSONDeserializer;
910
import com.jlbabilino.json.JSONDeserializerException;
1011
import com.jlbabilino.json.JSONParserException;
1112
import com.jlbabilino.json.JSONSerializer;
13+
import com.jlbabilino.json.JSONSerializerException;
1214

1315
import org.team2363.helixnavigator.global.Standards;
1416
import org.team2363.lib.ui.prompts.SavePrompt;
@@ -149,6 +151,9 @@ private final boolean openDocument(File file) {
149151
alert.setContentText("Could not parse JSON in file \"" + file.getName() + "\":" + e.getMessage());
150152
alert.showAndWait();
151153
return false;
154+
} catch (InvalidJSONTranslationConfiguration e) {
155+
logger.severe("Internal JSON translation configuration error.");
156+
return false;
152157
} catch (JSONDeserializerException e) {
153158
logger.finer("Could not deserialize JSON data in file \"" + file.getName() + "\":" + e.getMessage());
154159
Alert alert = new Alert(AlertType.ERROR);
@@ -206,6 +211,12 @@ private final boolean saveDocument() {
206211
try {
207212
JSONSerializer.serializeFile(getDocument(), saveLocation);
208213
return true;
214+
} catch (InvalidJSONTranslationConfiguration e) {
215+
logger.severe("Internal JSON translation configuration.");
216+
return false;
217+
} catch (JSONSerializerException e) {
218+
logger.severe("Internal JSON serialization error");
219+
return false;
209220
} catch (IOException e) {
210221
Alert alert = new Alert(AlertType.CONFIRMATION);
211222
alert.setTitle("File Error");
@@ -325,6 +336,12 @@ public final boolean requestExportWaypointBundle() {
325336
try {
326337
JSONSerializer.serializeFile(waypointBundle, saveLocation);
327338
return true;
339+
} catch (InvalidJSONTranslationConfiguration e) {
340+
logger.severe("Internal JSON translation configuration error.");
341+
return false;
342+
} catch (JSONSerializerException e) {
343+
logger.severe("Internal JSON serializer error.");
344+
return false;
328345
} catch (IOException e) {
329346
logger.finer("Error while saving waypoint bundle");
330347
return false;

app/src/main/java/org/team2363/helixnavigator/document/HDocument.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
import com.jlbabilino.json.DeserializedJSONConstructor;
2424
import com.jlbabilino.json.DeserializedJSONObjectValue;
2525
import com.jlbabilino.json.DeserializedJSONTarget;
26+
import com.jlbabilino.json.JSONDeserializable;
2627
import com.jlbabilino.json.JSONSerializable;
2728
import com.jlbabilino.json.SerializedJSONObjectValue;
29+
import com.jlbabilino.json.JSONEntry.JSONType;
2830

2931
import org.team2363.helixnavigator.document.field.image.HFieldImage;
3032
import org.team2363.helixnavigator.document.field.image.HReferenceFieldImage;
@@ -49,7 +51,8 @@
4951
*
5052
* @author Justin Babilino
5153
*/
52-
@JSONSerializable
54+
@JSONSerializable(JSONType.OBJECT)
55+
@JSONDeserializable({JSONType.OBJECT})
5356
public class HDocument {
5457

5558
private static final Logger logger = Logger.getLogger("org.team2363.helixnavigator.document");

app/src/main/java/org/team2363/helixnavigator/document/HFieldTarget.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
import com.jlbabilino.json.DeserializedJSONConstructor;
44
import com.jlbabilino.json.DeserializedJSONObjectValue;
55
import com.jlbabilino.json.DeserializedJSONTarget;
6+
import com.jlbabilino.json.JSONDeserializable;
67
import com.jlbabilino.json.JSONSerializable;
78
import com.jlbabilino.json.SerializedJSONObjectValue;
9+
import com.jlbabilino.json.JSONEntry.JSONType;
810

911
import javafx.beans.property.DoubleProperty;
1012
import javafx.beans.property.SimpleDoubleProperty;
1113

12-
@JSONSerializable
14+
@JSONSerializable(JSONType.OBJECT)
15+
@JSONDeserializable({JSONType.OBJECT})
1316
public class HFieldTarget {
1417

1518
private final DoubleProperty x = new SimpleDoubleProperty(this, "x", 0.0);

app/src/main/java/org/team2363/helixnavigator/document/HPath.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@
1818
import com.jlbabilino.json.DeserializedJSONConstructor;
1919
import com.jlbabilino.json.DeserializedJSONObjectValue;
2020
import com.jlbabilino.json.DeserializedJSONTarget;
21+
import com.jlbabilino.json.InvalidJSONTranslationConfiguration;
22+
import com.jlbabilino.json.JSONDeserializable;
2123
import com.jlbabilino.json.JSONSerializable;
2224
import com.jlbabilino.json.JSONSerializer;
25+
import com.jlbabilino.json.JSONSerializerException;
2326
import com.jlbabilino.json.SerializedJSONObjectValue;
27+
import com.jlbabilino.json.JSONEntry.JSONType;
2428

2529
import javafx.beans.property.ReadOnlyBooleanProperty;
2630
import javafx.beans.property.ReadOnlyBooleanWrapper;
@@ -33,7 +37,8 @@
3337
import javafx.collections.ObservableList;
3438
import javafx.scene.transform.Transform;
3539

36-
@JSONSerializable
40+
@JSONSerializable(JSONType.OBJECT)
41+
@JSONDeserializable({JSONType.OBJECT})
3742
public class HPath {
3843

3944
private final StringProperty name = new SimpleStringProperty(this, "name", "");
@@ -234,6 +239,10 @@ public Path toPath() {
234239

235240
@Override
236241
public String toString() {
237-
return JSONSerializer.serializeString(this);
242+
try {
243+
return JSONSerializer.serializeString(this);
244+
} catch (InvalidJSONTranslationConfiguration | JSONSerializerException e) {
245+
return "";
246+
}
238247
}
239248
}

app/src/main/java/org/team2363/helixnavigator/document/HPathElement.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22

33
import com.jlbabilino.json.DeserializedJSONObjectValue;
44
import com.jlbabilino.json.DeserializedJSONTarget;
5+
import com.jlbabilino.json.InvalidJSONTranslationConfiguration;
6+
import com.jlbabilino.json.JSONDeserializable;
57
import com.jlbabilino.json.JSONSerializable;
68
import com.jlbabilino.json.JSONSerializer;
9+
import com.jlbabilino.json.JSONSerializerException;
710
import com.jlbabilino.json.SerializedJSONObjectValue;
11+
import com.jlbabilino.json.JSONEntry.JSONType;
812

913
import javafx.beans.property.SimpleStringProperty;
1014
import javafx.beans.property.StringProperty;
1115

12-
@JSONSerializable
16+
@JSONSerializable(JSONType.OBJECT)
17+
@JSONDeserializable({JSONType.OBJECT})
1318
public abstract class HPathElement extends HSelectableElement {
1419

1520
private final StringProperty name = new SimpleStringProperty(this, "name", "");
@@ -33,6 +38,10 @@ public final String getName() {
3338

3439
@Override
3540
public String toString() {
36-
return JSONSerializer.serializeString(this);
41+
try {
42+
return JSONSerializer.serializeString(this);
43+
} catch (InvalidJSONTranslationConfiguration | JSONSerializerException e) {
44+
return "";
45+
}
3746
}
3847
}

app/src/main/java/org/team2363/helixnavigator/document/HRobotConfiguration.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
import com.jlbabilino.json.DeserializedJSONConstructor;
99
import com.jlbabilino.json.DeserializedJSONObjectValue;
1010
import com.jlbabilino.json.DeserializedJSONTarget;
11+
import com.jlbabilino.json.JSONDeserializable;
1112
import com.jlbabilino.json.JSONSerializable;
1213
import com.jlbabilino.json.SerializedJSONObjectValue;
14+
import com.jlbabilino.json.JSONEntry.JSONType;
1315

1416
import javafx.beans.property.DoubleProperty;
1517
import javafx.beans.property.IntegerProperty;
@@ -18,7 +20,8 @@
1820
import javafx.beans.property.SimpleIntegerProperty;
1921
import javafx.beans.property.SimpleObjectProperty;
2022

21-
@JSONSerializable
23+
@JSONSerializable(JSONType.OBJECT)
24+
@JSONDeserializable({JSONType.OBJECT})
2225
public class HRobotConfiguration {
2326

2427
private final IntegerProperty teamNumber = new SimpleIntegerProperty(this, "teamNumber", DefaultRobotConfiguration.TEAM_NUMBER);

app/src/main/java/org/team2363/helixnavigator/document/HTrajectory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99

1010
import com.jlbabilino.json.DeserializedJSONConstructor;
1111
import com.jlbabilino.json.DeserializedJSONEntry;
12+
import com.jlbabilino.json.JSONDeserializable;
1213
import com.jlbabilino.json.JSONEntry.JSONType;
1314
import com.jlbabilino.json.JSONSerializable;
1415
import com.jlbabilino.json.SerializedJSONEntry;
1516

1617
import javafx.beans.property.DoubleProperty;
1718
import javafx.beans.property.SimpleDoubleProperty;
1819

19-
@JSONSerializable(rootType = JSONType.ARRAY)
20+
@JSONSerializable(JSONType.ARRAY)
21+
@JSONDeserializable({JSONType.ARRAY})
2022
public class HTrajectory {
2123

2224
private final DoubleProperty timestamp = new SimpleDoubleProperty(this, "timestamp", 0.0);

app/src/main/java/org/team2363/helixnavigator/document/HTrajectorySample.java

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

55
import com.jlbabilino.json.DeserializedJSONConstructor;
66
import com.jlbabilino.json.DeserializedJSONObjectValue;
7+
import com.jlbabilino.json.JSONDeserializable;
78
import com.jlbabilino.json.JSONSerializable;
89
import com.jlbabilino.json.SerializedJSONObjectValue;
10+
import com.jlbabilino.json.JSONEntry.JSONType;
911

10-
@JSONSerializable
12+
@JSONSerializable(JSONType.OBJECT)
13+
@JSONDeserializable({JSONType.OBJECT})
1114
public class HTrajectorySample {
1215

1316
@SerializedJSONObjectValue(key = "ts")

0 commit comments

Comments
 (0)