1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-08-13 17:03:45 -04:00

Add Object.toJsonString() convenience extension method

This commit is contained in:
Reinhard Pointner 2018-08-16 14:04:09 +07:00
parent e2d867dc4d
commit 1a7e7b06c3

View File

@ -34,6 +34,7 @@ import java.util.logging.Level;
import org.codehaus.groovy.runtime.DefaultGroovyMethods; import org.codehaus.groovy.runtime.DefaultGroovyMethods;
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation; import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;
import groovy.json.JsonBuilder;
import groovy.lang.Closure; import groovy.lang.Closure;
import groovy.lang.Range; import groovy.lang.Range;
import net.filebot.MediaTypes; import net.filebot.MediaTypes;
@ -449,6 +450,10 @@ public class ScriptShellMethods {
return MediaDetection.isMovie(self, true); return MediaDetection.isMovie(self, true);
} }
public static Object toJsonString(Object object) {
return new JsonBuilder(object).toPrettyString();
}
public static String format(Date self, String format) { public static String format(Date self, String format) {
// XXX: org.apache.groovy.datetime.extensions.DateTimeExtensions is not registered for some reason in production (maybe a bug specific to Groovy 2.5.0) // XXX: org.apache.groovy.datetime.extensions.DateTimeExtensions is not registered for some reason in production (maybe a bug specific to Groovy 2.5.0)
return DateTimeFormatter.ofPattern(format, Locale.US).format(LocalDateTime.ofInstant(self.toInstant(), ZoneId.systemDefault())); return DateTimeFormatter.ofPattern(format, Locale.US).format(LocalDateTime.ofInstant(self.toInstant(), ZoneId.systemDefault()));