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

com.github.jackpanz.spring.beetl.ToJson Maven / Gradle / Ivy

The newest version!
package com.github.jackpanz.spring.beetl;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.beetl.core.Context;
import org.beetl.core.Function;

import java.io.IOException;

/**
 * Created by bj on 2017/6/19.
 */
public class ToJson implements Function {

    public ObjectMapper getObjectMapper() {
        return objectMapper;
    }

    public void setObjectMapper(ObjectMapper objectMapper) {
        this.objectMapper = objectMapper;
    }

    private ObjectMapper objectMapper;

    public ToJson() {

    }

    public ToJson(ObjectMapper objectMapper) {
        this.objectMapper = objectMapper;
    }

    @Override
    public Object call(Object[] paras, Context ctx) {
        Object obj = paras[0];
        if (obj != null) {
            try {
                ctx.byteWriter.writeString(objectMapper.writeValueAsString(obj));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return "";
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy