@@ -37,28 +37,32 @@ public class JSONLoadStrategy implements ImageAnnotationLoadStrategy {
3737 private static final String BOUNDING_POLYGON_SERIALIZED_NAME = "polygon" ;
3838 private static final String TAGS_SERIALIZED_NAME = "tags" ;
3939 private static final String PARTS_SERIALIZED_NAME = "parts" ;
40+ private static final String IMAGE_ATTRIBUTION_MESSAGE_PART = "element for image " ;
4041 private static final String POLYGON_MISSING_CATEGORY_ERROR_MESSAGE =
41- "Missing category field in bounding polygon element for image " ;
42+ "Missing category field in bounding polygon " + IMAGE_ATTRIBUTION_MESSAGE_PART ;
4243 private static final String POLYGON_INVALID_COORDINATES_ERROR_MESSAGE = "Invalid coordinate value(s) in polygon " +
43- "field for image " ;
44+ IMAGE_ATTRIBUTION_MESSAGE_PART ;
4445 private static final String POLYGON_INVALID_COORDINATE_NUMBER_ERROR_MESSAGE =
45- "Invalid number of coordinates in polygon " +
46- "field for image " ;
47- private static final String POLYGON_INVALID_TAGS_ERROR_MESSAGE = "Invalid tags value(s) in polygon element " +
48- "for image " ;
49- private static final String POLYGON_INVALID_PARTS_ERROR_MESSAGE = "Invalid parts value(s) in polygon element " +
50- "for image " ;
46+ "Invalid number of coordinates in polygon " + IMAGE_ATTRIBUTION_MESSAGE_PART ;
47+ private static final String POLYGON_INVALID_TAGS_ERROR_MESSAGE = "Invalid tags value(s) in polygon " +
48+ IMAGE_ATTRIBUTION_MESSAGE_PART ;
49+ private static final String POLYGON_INVALID_PARTS_ERROR_MESSAGE = "Invalid parts value(s) in polygon " +
50+ IMAGE_ATTRIBUTION_MESSAGE_PART ;
5151 private static final String BOX_MISSING_CATEGORY_ERROR_MESSAGE = "Missing category field in bounding box " +
52- "element for image " ;
52+ IMAGE_ATTRIBUTION_MESSAGE_PART ;
5353 private static final String BOX_INVALID_TAGS_ERROR_MESSAGE = "Invalid tags value(s) in bounding box " +
54- "element for image " ;
54+ IMAGE_ATTRIBUTION_MESSAGE_PART ;
5555 private static final String BOX_INVALID_PARTS_ERROR_MESSAGE = "Invalid parts value(s) in bounding box " +
56- "element for image " ;
57- private static final String MISSING_IMAGE_FILE_NAME_ERROR_MESSAGE = "Missing image fileName field for image " ;
58- private static final String MISSING_IMAGES_FIELD_ERROR_MESSAGE = "Missing images field in annotation." ;
59- private static final String MISSING_OBJECTS_FIELD_ERROR_MESSAGE = "Missing objects field for annotation of image " ;
60- private static final String MISSING_CATEGORY_NAME_ERROR_MESSAGE = "Missing category name for image " ;
61- private static final String MISSING_BOUNDING_SHAPE_ERROR_MESSAGE = "Missing bndbox or polygon field for image " ;
56+ IMAGE_ATTRIBUTION_MESSAGE_PART ;
57+ private static final String MISSING_IMAGE_FILE_NAME_ERROR_MESSAGE =
58+ "Missing image fileName " + IMAGE_ATTRIBUTION_MESSAGE_PART ;
59+ private static final String MISSING_IMAGES_FIELD_ERROR_MESSAGE = "Missing images element in annotation." ;
60+ private static final String MISSING_OBJECTS_FIELD_ERROR_MESSAGE =
61+ "Missing objects " + IMAGE_ATTRIBUTION_MESSAGE_PART ;
62+ private static final String MISSING_CATEGORY_NAME_ERROR_MESSAGE =
63+ "Missing category name " + IMAGE_ATTRIBUTION_MESSAGE_PART ;
64+ private static final String MISSING_BOUNDING_SHAPE_ERROR_MESSAGE =
65+ "Missing bndbox or polygon " + IMAGE_ATTRIBUTION_MESSAGE_PART ;
6266
6367 @ Override
6468 public IOResult load (Model model , Path path , DoubleProperty progress ) throws IOException {
@@ -170,7 +174,7 @@ public BoundingShapeDataDeserializer(List<IOResult.ErrorInfoEntry> unParsedFileE
170174
171175 @ Override
172176 public BoundingShapeData deserialize (JsonElement json , java .lang .reflect .Type type ,
173- JsonDeserializationContext context ) throws JsonParseException {
177+ JsonDeserializationContext context ) {
174178 final JsonObject jsonObject = json .getAsJsonObject ();
175179
176180 BoundingShapeData boundingShapeData = null ;
@@ -211,7 +215,7 @@ public ObjectCategoryDeserializer(List<IOResult.ErrorInfoEntry> unParsedFileErro
211215
212216 @ Override
213217 public ObjectCategory deserialize (JsonElement json , java .lang .reflect .Type type ,
214- JsonDeserializationContext context ) throws JsonParseException {
218+ JsonDeserializationContext context ) {
215219 final JsonObject jsonObject = json .getAsJsonObject ();
216220
217221 if (!jsonObject .has (OBJECT_CATEGORY_NAME_SERIALIZED_NAME )) {
@@ -255,8 +259,7 @@ public BoundsDeserializer(List<IOResult.ErrorInfoEntry> unParsedFileErrorMessage
255259 }
256260
257261 @ Override
258- public Bounds deserialize (JsonElement json , java .lang .reflect .Type type , JsonDeserializationContext context )
259- throws JsonParseException {
262+ public Bounds deserialize (JsonElement json , java .lang .reflect .Type type , JsonDeserializationContext context ) {
260263 final JsonObject jsonObject = json .getAsJsonObject ();
261264
262265 final Double minX = parseCoordinateField (jsonObject , BOUNDS_MIN_X_SERIALIZED_NAME );
@@ -290,7 +293,7 @@ private Double parseCoordinateField(JsonObject jsonObject, String name) {
290293 if (!jsonObject .has (name )) {
291294 unParsedFileErrorMessages
292295 .add (new IOResult .ErrorInfoEntry (annotationFileName ,
293- "Missing " + name + " field for image " +
296+ "Missing " + name + " " + IMAGE_ATTRIBUTION_MESSAGE_PART +
294297 currentFilename .get () + "." ));
295298 return null ;
296299 }
@@ -302,15 +305,15 @@ private Double parseCoordinateField(JsonObject jsonObject, String name) {
302305 } catch (ClassCastException | NumberFormatException e ) {
303306 unParsedFileErrorMessages .add (new IOResult .ErrorInfoEntry (annotationFileName ,
304307 "Invalid coordinate value for " + name +
305- " field for image " +
308+ " " + IMAGE_ATTRIBUTION_MESSAGE_PART +
306309 currentFilename .get () + "." ));
307310 return null ;
308311 }
309312
310313 if (!isValidRelativeCoordinate (value )) {
311314 unParsedFileErrorMessages .add (new IOResult .ErrorInfoEntry (annotationFileName ,
312315 "Invalid coordinate value for " + name +
313- " field for image " +
316+ " " + IMAGE_ATTRIBUTION_MESSAGE_PART +
314317 currentFilename .get () + "." ));
315318 return null ;
316319 }
@@ -339,7 +342,7 @@ public ImageMetaDataDeserializer(List<IOResult.ErrorInfoEntry> unParsedFileError
339342
340343 @ Override
341344 public ImageMetaData deserialize (JsonElement json , java .lang .reflect .Type type ,
342- JsonDeserializationContext context ) throws JsonParseException {
345+ JsonDeserializationContext context ) {
343346 final JsonObject jsonObject = json .getAsJsonObject ();
344347
345348 if (!jsonObject .has (IMAGE_FILE_NAME_SERIALIZED_NAME )) {
@@ -377,7 +380,7 @@ public ImageAnnotationDeserializer(List<IOResult.ErrorInfoEntry> unParsedFileErr
377380
378381 @ Override
379382 public ImageAnnotation deserialize (JsonElement json , java .lang .reflect .Type type ,
380- JsonDeserializationContext context ) throws JsonParseException {
383+ JsonDeserializationContext context ) {
381384
382385 if (!json .getAsJsonObject ().has (IMAGE_META_DATA_SERIALIZED_NAME )) {
383386 unParsedFileErrorMessages .add (new IOResult .ErrorInfoEntry (annotationFileName ,
@@ -430,10 +433,10 @@ public BoundingBoxDataDeserializer(List<IOResult.ErrorInfoEntry> unParsedFileErr
430433
431434 @ Override
432435 public BoundingBoxData deserialize (JsonElement json , java .lang .reflect .Type typeOfT ,
433- JsonDeserializationContext context ) throws JsonParseException {
436+ JsonDeserializationContext context ) {
434437 final JsonObject jsonObject = json .getAsJsonObject ();
435438
436- if (!jsonObject .has ("category" )) {
439+ if (!jsonObject .has (OBJECT_CATEGORY_SERIALIZED_NAME )) {
437440 unParsedFileErrorMessages .add (new IOResult .ErrorInfoEntry (annotationFileName ,
438441 BOX_MISSING_CATEGORY_ERROR_MESSAGE +
439442 currentFileName .get () + "." ));
@@ -499,7 +502,7 @@ public BoundingPolygonDataDeserializer(List<IOResult.ErrorInfoEntry> unParsedFil
499502
500503 @ Override
501504 public BoundingPolygonData deserialize (JsonElement json , java .lang .reflect .Type typeOfT ,
502- JsonDeserializationContext context ) throws JsonParseException {
505+ JsonDeserializationContext context ) {
503506 final JsonObject jsonObject = json .getAsJsonObject ();
504507
505508 if (!jsonObject .has (OBJECT_CATEGORY_SERIALIZED_NAME )) {
0 commit comments