From 19516ff1e4922a9f728e56366be0d5eede8d05d6 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 8 Oct 2013 12:26:39 -0700 Subject: [PATCH] Updated `nullValue` docs to be correct re: `Map`. --- README.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 68b1972..7b71aa3 100644 --- a/README.md +++ b/README.md @@ -202,10 +202,17 @@ use `nullValue()`: }); // throws MustacheException when executing the template because doesNotExist cannot be resolved -Note that any variable resolved against a `Map` context will be resolvable, but -will be treated as having the value null if the map contains no mapping for the -variable. Only variables resolved against Java object fields or methods risk -being unresolvable. +When using a `Map` as a context, `nullValue()` will only be used when the map +contains a mapping to `null`. If the map lacks a mapping for a given variable, +then it is considered unresolvable and throws an exception. + + Map map = new HashMap(); + map.put("exists", "Say"); + map.put("nullValued", null); + // no mapping exists for "doesNotExist" + String tmpl = "{{exists}} {{nullValued}} {{doesNotExist}}?"; + Mustache.compiler().nullValue("what").compile(tmpl).execute(map); + // throws MustacheException when executing the template because doesNotExist cannot be resolved Note that section behavior deviates from the above specification (for historical reasons and because it's kind of useful). By default, a section that