Version 3.1.6: fix Bridge, Serialiser, Progress:
[nikiroo-utils.git] / src / be / nikiroo / utils / serial / SerialUtils.java
index decf57525fb30336ab00dee5be5bb2952d5f8196..a1105a90d441352d71fa51faf5d56f8294f35318 100644 (file)
@@ -7,6 +7,7 @@ import java.lang.reflect.Array;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.UnknownFormatConversionException;
@@ -37,6 +38,7 @@ import be.nikiroo.utils.ImageUtils;
  * <li>Enum (any enum whose name and value is known by the caller)</li>
  * <li>java.awt.image.BufferedImage (as a {@link CustomSerializer})</li>
  * <li>An array of the above (as a {@link CustomSerializer})</li>
+ * <li>URL</li>
  * </ul>
  * 
  * @author niki
@@ -106,6 +108,30 @@ public class SerialUtils {
                        }
                });
 
+               // URL:
+               customTypes.put("java.net.URL", new CustomSerializer() {
+                       @Override
+                       protected String toString(Object value) {
+                               if (value != null) {
+                                       return ((URL) value).toString();
+                               }
+                               return null;
+                       }
+
+                       @Override
+                       protected Object fromString(String content) throws IOException {
+                               if (content != null) {
+                                       return new URL(content);
+                               }
+                               return null;
+                       }
+
+                       @Override
+                       protected String getType() {
+                               return "java.net.URL";
+                       }
+               });
+
                // Images (this is currently the only supported image type by default)
                customTypes.put("java.awt.image.BufferedImage", new CustomSerializer() {
                        @Override