List of usage examples for com.fasterxml.jackson.databind ObjectMapper writeValueAsString
@SuppressWarnings("resource") public String writeValueAsString(Object value) throws JsonProcessingException
From source file:dk.dma.msiproxy.common.util.JsonUtils.java
/** * Formats the entity as json data/*from ww w . ja v a2s .c o m*/ * * @param data the entity to format * @return the json data */ public static String toJson(Object data) throws IOException { ObjectMapper jsonMapper = new ObjectMapper(); return jsonMapper.writeValueAsString(data); }
From source file:edu.ub.ir.oof1.Util.JSONUtil.java
public static String modelsToJsonArray(List<AbstractModel> _models) { String out = ""; try {/*from w w w .j a v a 2 s.c o m*/ ObjectMapper mapper = new ObjectMapper(); out = mapper.writeValueAsString(_models); } catch (Exception e) { e.printStackTrace(); } return out; }
From source file:edu.ub.ir.oof1.Util.JSONUtil.java
public static String newsResultsToJson(NewsResults _news_results) { String out = ""; try {// w w w . j a v a2s .c o m ObjectMapper mapper = new ObjectMapper(); out = mapper.writeValueAsString(_news_results); } catch (Exception e) { e.printStackTrace(); } return out; }
From source file:edu.ub.ir.oof1.Util.JSONUtil.java
public static String modelToJsonObj(AbstractModel _model) { String out = ""; try {/* w w w .jav a2 s . com*/ ObjectMapper mapper = new ObjectMapper(); out = mapper.writeValueAsString(_model); } catch (Exception e) { e.printStackTrace(); } return out; }
From source file:org.moneta.utils.JsonUtils.java
/** * Will convert the given object to Json format. * @param jsonObject/*w w w .ja v a2 s . c om*/ * @return jsonText */ public static String serialize(Object jsonObject) { Validate.notNull(jsonObject, "Null object cannot be converted to Json"); ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(jsonObject); } catch (Exception e) { throw new MonetaException("Error converting object to Json", e).addContextValue("object", jsonObject); } }
From source file:com.wealdtech.configuration.ConfigurationGenerator.java
public static String generate(final Configuration configuration) { String result = null;/*from w ww.j av a 2s.co m*/ ObjectMapper mapper = ObjectMapperFactory.getDefaultMapper(); try { result = mapper.writeValueAsString(configuration); } catch (JsonProcessingException e) { System.err.println("Failed to generate configuration file: " + e.getLocalizedMessage()); } return result; }
From source file:io.fabric8.kubernetes.pipeline.devops.elasticsearch.BaseSendEvent.java
/** * Java main to test creating events in elasticsearch. Set the following ENV VARS to point to a local ES running in OpenShift * * PIPELINE_ELASTICSEARCH_HOST=elasticsearch.vagrant.f8 * ELASTICSEARCH_SERVICE_PORT=80//from w w w. jav a 2s . c o m * * @param event to send to elasticsearch */ public static void send(DTOSupport event, String type) { hudson.model.BuildListener listener = new StreamBuildListener(System.out, Charset.defaultCharset()); try { ObjectMapper mapper = JsonUtils.createObjectMapper(); String json = mapper.writeValueAsString(event); String id = ElasticsearchClient.createEvent(json, type, listener); listener.getLogger().println("Added events id: " + id); } catch (Exception e) { LOG.log(Level.SEVERE, "Error when sending build data: " + event, e); } }
From source file:sonata.kernel.vimadaptor.wrapper.openstack.javastackclient.JavaStackUtils.java
public static String convertYamlToJson(String yamlToConvert) throws IOException { ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory()); Object obj = yamlReader.readValue(yamlToConvert, Object.class); ObjectMapper jsonWriter = new ObjectMapper(); return jsonWriter.writeValueAsString(obj); }
From source file:io.acme.solution.domain.util.MementoBuilder.java
public static String flatten(final HashMap<String, Object> attributesMap) { final ObjectMapper mapper = new ObjectMapper(); try {//from w w w . j ava 2 s .c o m return mapper.writeValueAsString(attributesMap); } catch (JsonProcessingException exception) { log.debug("Failed to craete memento object"); log.trace("Failed to create memento object for the passed attributes map", exception); return null; } }
From source file:fr.assoba.open.sel.generator.LanguageExecutor.java
public static void execute(List<Namespace> namespaceList, IO io, String... languages) throws IOException, ScriptException { ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine jsEngine = factory.getEngineByName("JavaScript"); jsEngine.put("IO", io); jsEngine.eval(io.readFile("underscore.js")); jsEngine.eval(io.readFile("handlebars-v1.3.0.js")); ObjectMapper mapper = new ObjectMapper(); jsEngine.eval("namespaces=" + mapper.writeValueAsString(namespaceList)); for (String lang : languages) { if (generatorMap.containsKey(lang)) { generatorMap.get(lang).generate(namespaceList, io); } else {//www. j a v a2s . c o m jsEngine.eval(io.readFile(lang + ".js")); } } }