Skip to content

Commit 866e0be

Browse files
committed
Recuperate from having serialized a missing module.
We may have serialized that the module was not available or properly configured at the time of serialization. In that case, the submodel is only one information parameter. Instead of returning it, we try to instantiate a new model, so that the user is presented something par with the current configuration they have.
1 parent 9bf1b5b commit 866e0be

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

src/main/java/fiji/plugin/trackmate/helper/model/ParameterSweepModelIO.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import fiji.plugin.trackmate.helper.model.parameter.AbstractParamSweepModel;
5454
import fiji.plugin.trackmate.helper.model.parameter.AbstractParamSweepModelIO;
5555
import fiji.plugin.trackmate.helper.model.parameter.EnumParamSweepModel;
56+
import fiji.plugin.trackmate.helper.model.parameter.InfoParamSweepModel;
5657
import fiji.plugin.trackmate.helper.model.tracker.TrackerSweepModel;
5758
import fiji.plugin.trackmate.providers.DetectorProvider;
5859
import fiji.plugin.trackmate.providers.TrackerProvider;
@@ -315,8 +316,36 @@ public TrackerSweepModel deserialize( final JsonElement json, final Type typeOfT
315316
}
316317
}
317318

318-
// Normal case.
319-
return context.deserialize( element, Class.forName( "fiji.plugin.trackmate.helper.model.tracker." + type ) );
319+
// Deserialize from Json
320+
final TrackerSweepModel ds = ( TrackerSweepModel ) context.deserialize( element, Class.forName( "fiji.plugin.trackmate.helper.model.tracker." + type ) );
321+
322+
/*
323+
* We may have serialized that the module was not available or
324+
* properly configured at the time of serialization. In that
325+
* case, the submodel is only one information parameter. Instead
326+
* of returning it, we try to instantiate a new model, so that
327+
* the user is presented something par with the current
328+
* configuration they have.
329+
*/
330+
// Test if we serialized an error.
331+
if ( ds.models.size() == 1 )
332+
{
333+
final AbstractParamSweepModel< ? > sm = ds.models.values().iterator().next();
334+
if ( sm instanceof InfoParamSweepModel )
335+
{
336+
try
337+
{
338+
final Object obj2 = Class.forName( "fiji.plugin.trackmate.helper.model.tracker." + type ).getConstructor().newInstance();
339+
return ( TrackerSweepModel ) obj2;
340+
}
341+
catch ( InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e )
342+
{
343+
e.printStackTrace();
344+
}
345+
}
346+
}
347+
// Otherwise we return it.
348+
return ds;
320349
}
321350
catch ( final ClassNotFoundException cnfe )
322351
{

0 commit comments

Comments
 (0)