All Downloads are FREE. Search and download functionalities are using the official Maven repository.

liqp.filters.Json Maven / Gradle / Ivy

Go to download

A Java implementation of the Liquid templating engine backed up by an ANTLR grammar.

The newest version!
package liqp.filters;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import liqp.TemplateContext;
import liqp.TemplateParser;

public class Json extends Filter {
    @Override
    public Object apply(Object value, TemplateContext context, Object... params) {
        ObjectMapper mapper = context.getParser().mapper;

        try {
            return mapper.writeValueAsString(value);
        } catch (JsonProcessingException e) {
            context.addError(e);
            if (context.getErrorMode() == TemplateParser.ErrorMode.STRICT) {
                throw new RuntimeException(e.getMessage(), e);
            }
            return value;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy