Changeset 1737


Ignore:
Timestamp:
2010-10-12 09:44:15 (3 years ago)
Author:
jgou
Message:

add a json:serialize(obj) template function which produces a valid json string ; fixes #361

Location:
trunk/universe/kauri-template/src
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/universe/kauri-template/src/main/java/org/kauriproject/template/el/TemplateFunctionMapper.java

    r1549 r1737  
    2929        addDateFunctions(); 
    3030        addStringFunctions(); 
     31        addJsonFunctions(); 
    3132        // by doing this last, registered functions may override functions loaded above. 
    3233        addRegisteredFunctions(functionRegistry); 
     
    7374        } 
    7475    } 
     76     
     77    private void addJsonFunctions() { 
     78        String prefix = "json"; 
     79        Method[] methods = JsonFunctions.class.getDeclaredMethods(); 
     80        for (Method method : methods) { 
     81            addFunction(prefix, method.getName(), method); 
     82        } 
     83    } 
    7584 
    7685    private void addRegisteredFunctions(FunctionRegistry functionRegistry) { 
  • trunk/universe/kauri-template/src/test/java/org/kauriproject/template/TemplateExecutionTest.java

    r1688 r1737  
    2626import org.kauriproject.xml.sax.Saxable; 
    2727import org.w3c.dom.Document; 
     28import org.xml.sax.ContentHandler; 
     29import org.xml.sax.SAXException; 
    2830import org.xml.sax.helpers.AttributesImpl; 
    29 import org.xml.sax.SAXException; 
    30 import org.xml.sax.ContentHandler; 
    3131 
    3232public class TemplateExecutionTest extends TemplateTestBase { 
     
    189189        testFlow("/org/kauriproject/template/xmlvariables.xml", variables, true); 
    190190    } 
     191     
     192    public void testJsonVariables() throws Exception { 
     193        testFlow("/org/kauriproject/template/jsonvariables.xml", true); 
     194    } 
    191195} 
Note: See TracChangeset for help on using the changeset viewer.