Browse Source

changed encoder interface a bit, added a note how to add custom normalizers/encoders

Johannes Schmitt 14 years ago
parent
commit
239625f1dd

+ 19 - 0
Resources/doc/index.rst

@@ -145,6 +145,25 @@ There are several ways how you can customize the serialization process:
     2. Implementing NormalizableInterface
     3. Adding a Custom Normalizer
 
+Wiring Custom Normalizers/Encoders
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If you want to add custom normalizers, or encoders, you simply have to implement
+either the ``JMS\SerializerBundle\Serializer\Normalizer\NormalizerInterface`` or
+the ``JMS\SerializerBundle\Serializer\Encoder\EncoderInterface`` interface.
+
+For normalizers, you can then use the following tag:
+
+    <service id="my.custom.normalizer">
+        <tag name="jms_serializer.normalizer" />
+    </service>
+
+For encoders, you also have to pass the format:
+
+    <service id="my.custom.xml.encoder">
+        <tag name="jms_serializer.encoder" format="xml" />
+    </service>
+
 Annotations
 -----------
 

+ 0 - 2
Serializer/Encoder/EncoderInterface.php

@@ -6,6 +6,4 @@ interface EncoderInterface
 {
     function encode($data);
     function decode($data);
-    function supportsEncoding($data);
-    function supportsDecoding($data);
 }

+ 0 - 10
Serializer/Encoder/JsonEncoder.php

@@ -13,14 +13,4 @@ class JsonEncoder implements EncoderInterface
     {
         return json_decode($data, true);
     }
-
-    public function supportsEncoding($data)
-    {
-        return true;
-    }
-
-    public function supportsDecoding($data)
-    {
-        return false;
-    }
 }

+ 0 - 10
Serializer/Encoder/XmlEncoder.php

@@ -84,16 +84,6 @@ class XmlEncoder implements EncoderInterface
         return $this->parseXml($xml);
     }
 
-    public function supportsEncoding($data)
-    {
-        return true;
-    }
-
-    public function supportsDecoding($data)
-    {
-        return true;
-    }
-
     /**
      * @param DOMNode $node
      * @param string $val