List of usage examples for com.fasterxml.jackson.databind ObjectMapper ObjectMapper
public ObjectMapper()
From source file:com.shampan.db.collections.fragment.status.ReferenceInfo.java
public static ReferenceInfo getRefInfo(String jsonContent) { ReferenceInfo refInfo = null;/*from w w w. j a v a2 s. c om*/ try { ObjectMapper mapper = new ObjectMapper(); refInfo = mapper.readValue(jsonContent, ReferenceInfo.class); } catch (Exception ex) { ex.printStackTrace(); } return refInfo; }
From source file:com.pingcap.tikv.meta.DBInfoTest.java
@Test public void testSerialize() throws Exception { ObjectMapper mapper = new ObjectMapper(); String json = "{\"id\":1,\"db_name\":{\"O\":\"test\",\"L\":\"test\"},\"charset\":\"utf8\",\"collate\":\"utf8_bin\",\"state\":5}"; TiDBInfo dbInfo = mapper.readValue(json, TiDBInfo.class); assertEquals(dbInfo.getId(), 1);//from w ww. j av a 2 s . com assertEquals(dbInfo.getName(), "test"); assertEquals(dbInfo.getCharset(), "utf8"); assertEquals(dbInfo.getCollate(), "utf8_bin"); assertEquals(dbInfo.getSchemaState(), SchemaState.StatePublic); }
From source file:com.github.camellabs.iot.cloudlet.sdk.RestTemplates.java
public static RestTemplate defaultRestTemplate() { LOG.debug("Creating new default RestTemplate instance."); ObjectMapper objectMapper = new ObjectMapper().configure(FAIL_ON_UNKNOWN_PROPERTIES, false) .configure(FAIL_ON_EMPTY_BEANS, false).setSerializationInclusion(NON_NULL); objectMapper.getSerializationConfig().getDefaultVisibilityChecker().withFieldVisibility(PUBLIC_ONLY); MappingJackson2HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter( objectMapper);/* w ww .j a v a 2 s. com*/ return new RestTemplate(singletonList(jacksonConverter)); }
From source file:tachyon.master.JsonObject.java
/** Creates a JSON ObjectMapper configured not to close the underlying stream. */ public static ObjectMapper createObjectMapper() { // TODO: Could disable field name quoting, though this would produce technically invalid JSON // See: JsonGenerator.QUOTE_FIELD_NAMES and JsonParser.ALLOW_UNQUOTED_FIELD_NAMES return new ObjectMapper().configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false) .configure(SerializationFeature.CLOSE_CLOSEABLE, false); }
From source file:com.qubole.quark.planner.test.utilities.QuarkTestUtil.java
public static String toJson(String schema) throws JsonProcessingException { ImmutableList<String> defaultSchema = ImmutableList.of(schema); final ObjectMapper mapper = new ObjectMapper(); return mapper.writeValueAsString(defaultSchema); }
From source file:com.shampan.db.collections.fragment.common.Comment.java
public static Comment getCommentInfo(String jsonContent) { Comment commentInfo = null;//www. ja va 2 s . c om try { ObjectMapper mapper = new ObjectMapper(); commentInfo = mapper.readValue(jsonContent, Comment.class); } catch (Exception ex) { ex.printStackTrace(); } return commentInfo; }
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 {//from w ww . ja v a 2s.c o m jsEngine.eval(io.readFile(lang + ".js")); } } }
From source file:it.eng.spagobi.studio.console.model.bo.JsonTemplateGenerator.java
public static String transformToJson(Object bean) throws SavingEditorException { String result = null;/*from w w w . j a v a 2 s .c om*/ try { ObjectMapper mapper = new ObjectMapper(); //This option exclude object with null value from the serialization mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); //mapper.writeValueAsString(bean); result = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(bean); } catch (JsonGenerationException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; }
From source file:org.mayocat.rest.jackson.DateTimeISO8601SerializerTest.java
private final ObjectMapper jodaMapper() { ObjectMapper mapper = new ObjectMapper(); SimpleModule testModule = new SimpleModule("MyModule", new Version(1, 0, 0, null)); testModule.addSerializer(new DateTimeISO8601Serializer()); mapper.registerModule(testModule);/*from ww w . j a v a 2 s . c om*/ return mapper; }
From source file:org.maxur.perfmodel.backend.rest.PMObjectMapperProvider.java
private static ObjectMapper createDefaultMapper() { final ObjectMapper result = new ObjectMapper(); result.configure(SerializationFeature.INDENT_OUTPUT, true); return result; }