List of usage examples for com.fasterxml.jackson.databind ObjectMapper ObjectMapper
public ObjectMapper()
From source file:com.crm.earnify.request.action.ActionModel.java
@Override public String toJSONString() { try {/*from w w w .j a v a 2s.c o m*/ return new ObjectMapper().writeValueAsString(this); } catch (JsonProcessingException e) { e.printStackTrace(); } return new String(); }
From source file:org.mycontroller.standalone.api.jaxrs.utils.RestUtils.java
public static ObjectMapper getObjectMapper() { if (OBJECT_MAPPER == null) { OBJECT_MAPPER = new ObjectMapper(); OBJECT_MAPPER.configure(SerializationFeature.INDENT_OUTPUT, true); // this creates a 'configured' mapper OBJECT_MAPPER.setSerializationInclusion(Include.NON_NULL); OBJECT_MAPPER.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); OBJECT_MAPPER.addMixIn(Node.class, NodeMixinForScript.class); }/*from w w w. j a v a 2s.co m*/ return OBJECT_MAPPER; }
From source file:io.vertx.test.core.JsonMapperTest.java
@Test public void testGetSetMapper() { ObjectMapper mapper = Json.mapper;/* ww w . j ava 2 s.co m*/ assertNotNull(mapper); ObjectMapper newMapper = new ObjectMapper(); Json.mapper = newMapper; assertSame(newMapper, Json.mapper); Json.mapper = mapper; }
From source file:com.hollowsoft.library.utility.utility.JsonParser.java
/** * * @param json/*from w w w .j av a 2s . co m*/ * @return * @throws JsonProcessingException * @throws IOException */ public static <T> JsonNode toJsonNode(final String json) throws JsonProcessingException, IOException { if (json == null) { throw new IllegalArgumentException("The json cannot be null."); } return new ObjectMapper().reader().readTree(json); }
From source file:org.jboss.aerogear.sync.jsonpatch.JsonMapper.java
private static ObjectMapper createObjectMapper() { om = new ObjectMapper(); final SimpleModule module = new SimpleModule("JsonMergePatch", new Version(1, 0, 0, null, "aerogear", "sync")); module.addDeserializer(JsonPatchEdit.class, new EditDeserializer()); module.addSerializer(JsonPatchEdit.class, new EditSerializer()); module.addDeserializer(JsonPatchMessage.class, new PatchMessageDeserializer()); module.addSerializer(JsonPatchMessage.class, new PatchMessageSerializer()); om.registerModule(module);//from w w w. j av a 2 s .co m return om; }
From source file:org.axway.grapes.commons.utils.JsonUtils.java
/** * Un-serialize a Json into Module/*from w w w .java2 s . com*/ * @param module String * @return Module * @throws IOException */ public static Module unserializeModule(final String module) throws IOException { final ObjectMapper mapper = new ObjectMapper(); mapper.disable(MapperFeature.USE_GETTERS_AS_SETTERS); return mapper.readValue(module, Module.class); }
From source file:com.orange.clara.cloud.servicedbdumper.converter.MetadataConverter.java
@Override public String convertToDatabaseColumn(Metadata metadata) { if (metadata == null) { return null; }//from w w w .j a v a2 s . c o m ObjectMapper objectMapper = new ObjectMapper(); try { return objectMapper.writeValueAsString(metadata); } catch (JsonProcessingException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:com.shampan.db.codec.UserCodec.java
@Override public UserDAO decode(BsonReader reader, DecoderContext decoderContext) { Document document = documentCodec.decode(reader, decoderContext); ObjectMapper mapper = new ObjectMapper(); UserDAO user = new UserDAO(); try {// w w w. j a va 2 s . c o m user = mapper.readValue(document.toJson().toString(), UserDAO.class); } catch (Exception ex) { ex.printStackTrace(); } return user; }
From source file:nl.ortecfinance.opal.jacksonweb.SimulationResponseTest.java
@Test public void testJsonIgnore() throws IOException { SimulationResponse resp = new SimulationResponse(); resp.setCapitalGoalProbabilities(Arrays.asList(new Double(10), null, new Double(33))); StringWriter sr = new StringWriter(); ObjectMapper om = new ObjectMapper(); SimpleModule module = new SimpleModule(); // module.addSerializer(List<Double[]>.class, new ListOfDoubleArraySerializer()); module.addSerializer(Double[].class, new MyDoubleArraySerializer()); om.registerModule(module);// w ww.j a v a2 s . co m om.setSerializationInclusion(JsonInclude.Include.NON_NULL); om.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); om.writeValue(sr, resp); System.out.println("SimulationResponse=" + sr); }
From source file:com.hortonworks.registries.storage.util.StorageUtils.java
public static <T extends Storable> T jsonToStorable(String json, Class<T> clazz) throws IOException { ObjectMapper mapper = new ObjectMapper(); return mapper.readValue(json, clazz); }