diff --git a/source/net/filebot/cli/ScriptShellMethods.java b/source/net/filebot/cli/ScriptShellMethods.java index 166890b9..bc3d1d9d 100644 --- a/source/net/filebot/cli/ScriptShellMethods.java +++ b/source/net/filebot/cli/ScriptShellMethods.java @@ -26,14 +26,12 @@ import java.util.TreeSet; import org.codehaus.groovy.runtime.DefaultGroovyMethods; -import com.cedarsoftware.util.io.JsonReader; -import com.cedarsoftware.util.io.JsonWriter; - import groovy.lang.Closure; import groovy.lang.Range; import net.filebot.MediaTypes; import net.filebot.MetaAttributeView; import net.filebot.media.MediaDetection; +import net.filebot.media.MetaAttributes; import net.filebot.similarity.NameSimilarityMetric; import net.filebot.similarity.Normalization; import net.filebot.similarity.SimilarityMetric; @@ -352,11 +350,11 @@ public class ScriptShellMethods { } public static String objectToJson(Object self) throws IOException { - return JsonWriter.objectToJson(self); + return MetaAttributes.toJson(self); } public static Object jsonToObject(String self) throws IOException { - return JsonReader.jsonToJava(self); + return MetaAttributes.toObject(self); } public static File getStructurePathTail(File self) throws Exception { diff --git a/source/net/filebot/format/MediaBindingBean.java b/source/net/filebot/format/MediaBindingBean.java index 2ba1b373..ae331fc6 100644 --- a/source/net/filebot/format/MediaBindingBean.java +++ b/source/net/filebot/format/MediaBindingBean.java @@ -36,8 +36,6 @@ import java.util.Objects; import java.util.Optional; import java.util.regex.Pattern; -import com.cedarsoftware.util.io.JsonWriter; - import net.filebot.ApplicationFolder; import net.filebot.Cache; import net.filebot.CacheType; @@ -47,6 +45,7 @@ import net.filebot.MetaAttributeView; import net.filebot.Settings; import net.filebot.WebServices; import net.filebot.hash.HashType; +import net.filebot.media.MetaAttributes; import net.filebot.media.NamingStandard; import net.filebot.mediainfo.MediaInfo; import net.filebot.mediainfo.MediaInfo.StreamKind; @@ -990,7 +989,7 @@ public class MediaBindingBean { @Define("json") public String getInfoObjectDump() { - return JsonWriter.objectToJson(infoObject); + return MetaAttributes.toJson(infoObject); } public File getInferredMediaFile() { diff --git a/source/net/filebot/media/MetaAttributes.java b/source/net/filebot/media/MetaAttributes.java index c37b8a9a..2b606f4f 100644 --- a/source/net/filebot/media/MetaAttributes.java +++ b/source/net/filebot/media/MetaAttributes.java @@ -60,7 +60,7 @@ public class MetaAttributes { public void setObject(Object object) { try { - metaAttributeView.put(METADATA_KEY, JsonWriter.objectToJson(object, singletonMap(JsonWriter.TYPE_NAME_MAP, JSON_TYPE_MAP))); + metaAttributeView.put(METADATA_KEY, toJson(object)); } catch (Exception e) { throw new RuntimeException(e); } @@ -68,13 +68,9 @@ public class MetaAttributes { public Object getObject() { try { - String jsonObject = metaAttributeView.get(METADATA_KEY); - if (jsonObject != null && jsonObject.length() > 0) { - Map options = new HashMap(2); - options.put(JsonReader.TYPE_NAME_MAP, JSON_TYPE_MAP); - - // options must be a modifiable map - return JsonReader.jsonToJava(jsonObject, options); + String json = metaAttributeView.get(METADATA_KEY); + if (json != null && json.length() > 0) { + return toObject(json); } } catch (Exception e) { throw new RuntimeException(e); @@ -87,4 +83,20 @@ public class MetaAttributes { metaAttributeView.put(METADATA_KEY, null); } + public static String toJson(Object object) { + Map options = new HashMap(); + options.put(JsonWriter.TYPE_NAME_MAP, MetaAttributes.JSON_TYPE_MAP); + options.put(JsonWriter.SKIP_NULL_FIELDS, true); + + return JsonWriter.objectToJson(object, options); + } + + public static Object toObject(String json) { + Map options = new HashMap(); + options.put(JsonReader.TYPE_NAME_MAP, JSON_TYPE_MAP); + + // options must be a modifiable map + return JsonReader.jsonToJava(json, options); + } + } diff --git a/source/net/filebot/ui/rename/FormatDialog.java b/source/net/filebot/ui/rename/FormatDialog.java index 9218cf36..62a7f4ec 100644 --- a/source/net/filebot/ui/rename/FormatDialog.java +++ b/source/net/filebot/ui/rename/FormatDialog.java @@ -58,9 +58,6 @@ import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; import org.fife.ui.rsyntaxtextarea.SyntaxConstants; import org.fife.ui.rtextarea.RTextScrollPane; -import com.cedarsoftware.util.io.JsonReader; -import com.cedarsoftware.util.io.JsonWriter; - import net.filebot.ResourceManager; import net.filebot.Settings; import net.filebot.UserFiles; @@ -68,6 +65,7 @@ import net.filebot.format.BindingException; import net.filebot.format.ExpressionFormat; import net.filebot.format.MediaBindingBean; import net.filebot.mac.MacAppUtilities; +import net.filebot.media.MetaAttributes; import net.filebot.mediainfo.MediaInfo; import net.filebot.util.DefaultThreadFactory; import net.filebot.util.ExceptionUtilities; @@ -397,7 +395,7 @@ public class FormatDialog extends JDialog { try { // restore sample from user preferences String sample = mode.persistentSample().getValue(); - info = JsonReader.jsonToJava(sample); + info = MetaAttributes.toObject(sample); if (info == null) { throw new NullPointerException(); } @@ -406,7 +404,7 @@ public class FormatDialog extends JDialog { // restore sample from application properties ResourceBundle bundle = ResourceBundle.getBundle(getClass().getName()); String sample = bundle.getString(mode.key() + ".sample"); - info = JsonReader.jsonToJava(sample); + info = MetaAttributes.toObject(sample); } catch (Exception illegalSample) { debug.log(Level.SEVERE, "Illegal Sample", e); } @@ -594,7 +592,7 @@ public class FormatDialog extends JDialog { // remember sample try { - mode.persistentSample().setValue(info == null ? "" : JsonWriter.objectToJson(info)); + mode.persistentSample().setValue(info == null ? "" : MetaAttributes.toJson(info)); persistentSampleFile.setValue(file == null ? "" : sample.getFileObject().getAbsolutePath()); } catch (Exception e) { debug.log(Level.WARNING, e.getMessage(), e); diff --git a/source/net/filebot/ui/rename/RenamePanel.java b/source/net/filebot/ui/rename/RenamePanel.java index 5286f827..be84421b 100644 --- a/source/net/filebot/ui/rename/RenamePanel.java +++ b/source/net/filebot/ui/rename/RenamePanel.java @@ -21,7 +21,6 @@ import java.awt.event.ActionEvent; import java.io.File; import java.util.ArrayList; import java.util.EnumSet; -import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -50,7 +49,6 @@ import javax.swing.SwingWorker; import javax.swing.border.CompoundBorder; import javax.swing.border.TitledBorder; -import com.cedarsoftware.util.io.JsonWriter; import com.google.common.eventbus.Subscribe; import ca.odell.glazedlists.EventList; @@ -622,10 +620,6 @@ public class RenamePanel extends JComponent { private String getDebugInfo() throws Exception { StringBuilder sb = new StringBuilder(); - Map options = new HashMap(2); - options.put(JsonWriter.TYPE_NAME_MAP, MetaAttributes.JSON_TYPE_MAP); - options.put(JsonWriter.SKIP_NULL_FIELDS, true); - for (Match m : renameModel.matches()) { String f = getStructurePathTail(m.getCandidate()).getPath(); Object v = m.getValue(); @@ -635,7 +629,7 @@ public class RenamePanel extends JComponent { v = new SimpleFileInfo(getStructurePathTail((File) v).getPath(), ((File) v).length()); } - sb.append(f).append('\t').append(JsonWriter.objectToJson(v, options)).append('\n'); + sb.append(f).append('\t').append(MetaAttributes.toJson(v)).append('\n'); } return sb.toString();