json: rename and improve the quick and easy `deserialize_json`
authorAlexis Laferrière <alexis.laf@xymus.net>
Tue, 8 May 2018 23:52:02 +0000 (19:52 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Tue, 8 May 2018 23:52:40 +0000 (19:52 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/json/README.md
lib/json/serialization_read.nit

index b964d1c..94539c3 100644 (file)
@@ -107,7 +107,7 @@ The type to recreate is either declared or inferred:
 3. If all else fails, `JsonDeserializer` uses the static type of the attribute,
    or the type name passed to `deserialize`.
 
-The method `from_json_string` is a shortcut to `JsonDeserializer` which prints
+The method `deserialize_json` is a shortcut to `JsonDeserializer` which prints
 errors to the console. It is fit only for small scripts and other quick and dirty usage.
 
 ### Example
index 8dd73f7..4b71cea 100644 (file)
@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Services to read JSON: `from_json_string` and `JsonDeserializer`
+# Services to read JSON: `deserialize_json` and `JsonDeserializer`
 module serialization_read
 
 import serialization::caching
@@ -364,15 +364,17 @@ redef class Text
 
        # Deserialize a `nullable Object` from this JSON formatted string
        #
+       # If a `static_type` is given, only subtypes of the `static_type` are accepted.
+       #
        # Warning: Deserialization errors are reported with `print_error` and
        # may be returned as a partial object or as `null`.
        #
        # This method is not appropriate when errors need to be handled programmatically,
        # manually use a `JsonDeserializer` in such cases.
-       fun from_json_string: nullable Object
+       fun deserialize_json(static_type: nullable String): nullable Object
        do
                var deserializer = new JsonDeserializer(self)
-               var res = deserializer.deserialize
+               var res = deserializer.deserialize(static_type)
                if deserializer.errors.not_empty then
                        print_error "Deserialization Errors: {deserializer.errors.join(", ")}"
                end