List of usage examples for com.fasterxml.jackson.databind ObjectMapper writeValueAsString
@SuppressWarnings("resource") public String writeValueAsString(Object value) throws JsonProcessingException
From source file:org.craftercms.social.migration.util.scripting.ScriptUtils.java
public static String toJson(Object o) throws JsonProcessingException { final ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.getSerializationConfig().without(SerializationFeature.FAIL_ON_EMPTY_BEANS); mapper.getSerializationConfig().with(SerializationFeature.WRITE_NULL_MAP_VALUES, SerializationFeature.WRITE_EMPTY_JSON_ARRAYS); return mapper.writeValueAsString(o); }
From source file:com.qubole.quark.planner.test.PartialCubeTest.java
protected static SqlQueryParser getParser(String filter) throws JsonProcessingException, QuarkException { Properties info = new Properties(); info.put("unitTestMode", "true"); info.put("schemaFactory", "com.qubole.quark.planner.test.PartialCubeSchemaFactory"); ImmutableList<String> defaultSchema = ImmutableList.of("TPCDS"); final ObjectMapper mapper = new ObjectMapper(); info.put("defaultSchema", mapper.writeValueAsString(defaultSchema)); info.put("filter", filter); return new SqlQueryParser(info); }
From source file:com.netflix.genie.web.data.services.jpa.JpaServiceUtils.java
static <D extends CommonDTO, E extends BaseEntity> void setEntityMetadata(final ObjectMapper mapper, final D dto, final E entity) { if (dto.getMetadata().isPresent()) { try {/* ww w .j a v a2 s . com*/ entity.setMetadata(mapper.writeValueAsString(dto.getMetadata().get())); } catch (final JsonProcessingException jpe) { // Should never happen. Swallow and set to null as metadata is not Genie critical log.error("Invalid JSON, unable to convert to string", jpe); entity.setMetadata(null); } } else { entity.setMetadata(null); } }
From source file:com.netflix.conductor.server.ConductorServer.java
private static void createKitchenSink(int port) throws Exception { List<TaskDef> taskDefs = new LinkedList<>(); for (int i = 0; i < 40; i++) { taskDefs.add(new TaskDef("task_" + i, "task_" + i, 1, 0)); }/*ww w .j av a 2s . com*/ taskDefs.add(new TaskDef("search_elasticsearch", "search_elasticsearch", 1, 0)); Client client = Client.create(); ObjectMapper om = new ObjectMapper(); client.resource("http://localhost:" + port + "/api/metadata/taskdefs").type(MediaType.APPLICATION_JSON) .post(om.writeValueAsString(taskDefs)); InputStream stream = Main.class.getResourceAsStream("/kitchensink.json"); client.resource("http://localhost:" + port + "/api/metadata/workflow").type(MediaType.APPLICATION_JSON) .post(stream); stream = Main.class.getResourceAsStream("/sub_flow_1.json"); client.resource("http://localhost:" + port + "/api/metadata/workflow").type(MediaType.APPLICATION_JSON) .post(stream); String input = "{\"task2Name\":\"task_5\"}"; client.resource("http://localhost:" + port + "/api/workflow/kitchensink").type(MediaType.APPLICATION_JSON) .post(input); logger.info("Kitchen sink workflows are created!"); }
From source file:org.shareok.data.webserv.WebUtil.java
public static ModelAndView getServerList(ModelAndView model, RepoServerService serverService) throws JsonProcessingException { Map<String, String> serverList = serverService.getServerNameIdList(); if (null != serverList && serverList.size() > 0) { ObjectMapper mapper = new ObjectMapper(); Collection<String> ids = serverList.values(); List<RepoServer> serverObjList = serverService.getServerObjList(ids); String serverListJson = mapper.writeValueAsString(serverList); model.addObject("serverList", serverListJson); model.addObject("serverObjList", mapper.writeValueAsString(serverObjList)); } else {//w w w . j a v a 2 s. c o m // model.addObject("emptyServerList", "There are NO servers set up."); } return model; }
From source file:io.confluent.kafka.connect.source.Data.java
public static Map<String, String> settings(File targetDir) { SchemaConfig config = schemaConfig(); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); Map<String, String> result = new LinkedHashMap<>(); try {//from w ww . j a va 2 s . c o m String content = objectMapper.writeValueAsString(config); result.put(SpoolDirectoryConfig.CSV_SCHEMA_CONF, content); } catch (JsonProcessingException e) { throw new IllegalStateException(e); } File inputDirectory = new File(targetDir, "input"); inputDirectory.mkdirs(); result.put(SpoolDirectoryConfig.INPUT_PATH_CONFIG, inputDirectory.getAbsolutePath()); File finishDirectory = new File(targetDir, "finished"); result.put(SpoolDirectoryConfig.FINISHED_PATH_CONFIG, finishDirectory.getAbsolutePath()); finishDirectory.mkdirs(); File errorDirectory = new File(targetDir, "error"); result.put(SpoolDirectoryConfig.ERROR_PATH_CONFIG, errorDirectory.getAbsolutePath()); errorDirectory.mkdirs(); result.put(SpoolDirectoryConfig.TOPIC_CONF, TOPIC); // result.put(SpoolDirectoryConfig.KEY_FIELDS_CONF, "id"); result.put(SpoolDirectoryConfig.CSV_FIRST_ROW_AS_HEADER_CONF, "true"); result.put(SpoolDirectoryConfig.INPUT_FILE_PATTERN_CONF, "^.+\\.csv$"); result.put(SpoolDirectoryConfig.CSV_NULL_FIELD_INDICATOR_CONF, CSVReaderNullFieldIndicator.BOTH.name()); result.put(SpoolDirectoryConfig.CSV_PARSER_TIMESTAMP_DATE_FORMATS_CONF, "yyyy-MM-dd'T'HH:mm:ss'Z'"); result.put(SpoolDirectoryConfig.RECORD_PROCESSOR_CLASS_CONF, CSVRecordProcessor.class.getName()); result.put(SpoolDirectoryConfig.BATCH_SIZE_CONF, "100"); result.put(SpoolDirectoryConfig.CSV_SCHEMA_NAME_CONF, Data.class.getName() + "Schema"); return result; }
From source file:com.microsoft.windowsazure.services.media.samples.contentprotection.playreadywidevine.Program.java
private static String configureWidevineLicenceTemplate() throws JsonProcessingException { // Configure Widevine License Template and serialize it to JSON WidevineMessage message = new WidevineMessage(); message.setAllowedTrackTypes(AllowedTrackTypes.SD_HD); ContentKeySpecs ckspecs = new ContentKeySpecs(); message.setContentKeySpecs(new ContentKeySpecs[] { ckspecs }); ckspecs.setRequiredOutputProtection(new RequiredOutputProtection()); ckspecs.getRequiredOutputProtection().setHdcp(Hdcp.HDCP_NONE); ckspecs.setSecurityLevel(1);/*from w w w.java2 s . com*/ ckspecs.setTrackType("SD"); message.setPolicyOverrides(new Object() { public boolean can_play = true; public boolean can_persist = true; public boolean can_renew = false; }); ObjectMapper mapper = new ObjectMapper(); return mapper.writeValueAsString(message); }
From source file:com.hortonworks.streamline.streams.runtime.splitjoin.SplitJoinTest.java
protected static void checkActionWriteReadJsons(Action action) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); final String value = objectMapper.writeValueAsString(action); log.info("####### value = " + value); Class<? extends Action> actionClass = Action.class; Action actionRead = objectMapper.readValue(value, actionClass); log.info("####### actionRead = " + actionRead); }
From source file:org.zodiark.protocol.Envelope.java
private final static String encodeJSON(Object data, ObjectMapper mapper) throws JsonProcessingException { if (String.class.isAssignableFrom(data.getClass())) { return data.toString(); }// w ww . j a v a 2 s . com return mapper.writeValueAsString(data); }
From source file:com.company.et.service.JsonService.java
public static String objectToString(Object obj) throws IOException, ParseException { ObjectMapper mapper = new ObjectMapper(); // ? json'a mapper.configure(SerializationFeature.INDENT_OUTPUT, true); mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); String jsonString = mapper.writeValueAsString(obj); return jsonString; }