List of usage examples for com.fasterxml.jackson.databind ObjectMapper registerModule
public ObjectMapper registerModule(Module module)
From source file:com.company.et.service.JsonService.java
public static Professor[] jsonToObjectProfessorArray(String json) throws IOException, ParseException { ObjectMapper mapper = new ObjectMapper(); List<String> json_list = split(json); Professor[] profs = new Professor[json_list.size()]; SimpleModule testModule = new SimpleModule("MyModule", new Version(1, 0, 0, null)) .addDeserializer(Professor.class, new ProfessorDeserializer()); mapper.registerModule(testModule); for (int i = 0; i < json_list.size(); i++) { //System.out.println(json_list.get(i)); profs[i] = mapper.readValue(json_list.get(i), Professor.class); }/*w w w .ja va 2s . co m*/ return profs; }
From source file:uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser.java
public static ObjectMapper createDefaultMapper() { final ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); mapper.configure(SerializationFeature.CLOSE_CLOSEABLE, true); mapper.registerModule(getCloseableIterableDeserialiserModule()); // Use the 'setFilters' method so it is compatible with older versions of jackson mapper.setFilters(getFilterProvider()); return mapper; }
From source file:com.reprezen.swagedit.model.Model.java
protected static ObjectMapper createMapper() { final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); final SimpleModule module = new SimpleModule(); module.addDeserializer(AbstractNode.class, new NodeDeserializer()); mapper.registerModule(module); return mapper; }
From source file:com.groupdocs.sdk.common.ApiInvoker.java
@SuppressWarnings("unchecked") public static Object deserialize(String json, String containerType, @SuppressWarnings("rawtypes") Class cls) throws ApiException { try {/*from ww w . j a v a 2s . co m*/ ObjectMapper mapper = JsonUtil.getJsonMapper(); SimpleModule m = new SimpleModule(PACKAGE_NAME, Version.unknownVersion()); m.addDeserializer(Date.class, new CustomDateDeserializer(new DateDeserializer())); mapper.registerModule(m); if ("List".equals(containerType)) { JavaType typeInfo = mapper.getTypeFactory().constructCollectionType(List.class, cls); List<?> response = (List<?>) mapper.readValue(json, typeInfo); return response; } else if (String.class.equals(cls)) { return json; } else { return mapper.readValue(json, cls); } } catch (IOException e) { throw new ApiException(500, e.getMessage()); } }
From source file:com.bazaarvoice.jolt.JsonUtilImpl.java
public static void configureStockJoltObjectMapper(ObjectMapper objectMapper) { // All Json maps should be deserialized into LinkedHashMaps. SimpleModule stockModule = new SimpleModule("stockJoltMapping", new Version(1, 0, 0, null, null, null)) .addAbstractTypeMapping(Map.class, LinkedHashMap.class); objectMapper.registerModule(stockModule); // allow the mapper to parse JSON with comments in it objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); }
From source file:com.evrythng.java.wrapper.util.JSONUtils.java
/** * Creates a pre-configured {@link ObjectMapper}. *//*from www . j a v a 2s . com*/ public static ObjectMapper createObjectMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.setDateFormat(new ISO8601DateFormat()); mapper.registerModule(new CoreModule()); return mapper; }
From source file:it.polimi.diceH2020.plugin.control.FileManager.java
/** * Builds the JSON representation of the current Configuration and * eventually dumps it on a file./*from w w w . ja v a 2s.c o m*/ */ public static void generateInputJson() { Configuration conf = Configuration.getCurrent(); // TODO: REMOVE InstanceDataMultiProvider data = InstanceDataMultiProviderGenerator.build(); data.setId(conf.getID()); setMapJobProfile(data, conf); setMapClassParameters(data, conf); if (conf.getIsPrivate()) { data.setMapPublicCloudParameters(null); setPrivateParameters(data); } else { // Set MapVMConfigurations data.setMapVMConfigurations(null); data.setPrivateCloudParameters(null); if (conf.getHasLtc()) { setEtaR(data, conf); } else { data.setMapPublicCloudParameters(null); } } setMachineLearningProfile(data, conf); if (!Configuration.getCurrent().canSend()) { return; } // Generate Json ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new Jdk8Module()); try { mapper.writerWithDefaultPrettyPrinter() .writeValue(new File(Preferences.getSavingDir() + conf.getID() + ".json"), data); } catch (JsonProcessingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.jongo.marshall.jackson.JacksonProcessor.java
public static ObjectMapper createPreConfiguredMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(AUTO_DETECT_GETTERS, false); mapper.configure(AUTO_DETECT_SETTERS, false); mapper.setSerializationInclusion(NON_NULL); mapper.setVisibilityChecker(VisibilityChecker.Std.defaultInstance().withFieldVisibility(ANY)); SimpleModule module = new SimpleModule("jongo", new Version(1, 0, 0, null, null, null)); addBSONTypeSerializers(module);/* w w w . j av a 2 s . c o m*/ mapper.registerModule(module); return mapper; }
From source file:org.mango.marshall.jackson.JacksonProcessor.java
public static ObjectMapper createPreConfiguredMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(AUTO_DETECT_GETTERS, false); mapper.configure(AUTO_DETECT_SETTERS, false); mapper.setSerializationInclusion(NON_NULL); mapper.setVisibilityChecker(VisibilityChecker.Std.defaultInstance().withFieldVisibility(ANY)); SimpleModule module = new SimpleModule("mango", new Version(1, 0, 0, null, null, null)); addBSONTypeSerializers(module);/*w ww .j av a 2 s .co m*/ mapper.registerModule(module); return mapper; }
From source file:org.openmhealth.schema.configuration.JacksonConfiguration.java
public static ObjectMapper newObjectMapper() { ObjectMapper objectMapper = new ObjectMapper(); // we represent JSON numbers as Java BigDecimals objectMapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS); // we serialize dates, date times, and times as strings, not numbers objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); // we preserve time zone offsets when deserializing objectMapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE); // we default to the ISO8601 format for JSR-310 and support Optional objectMapper.registerModule(new JavaTimeModule()); objectMapper.registerModule(new Jdk8Module()); // but we have to explicitly support the RFC3339 format over ISO8601 to make JSON Schema happy, specifically to // prevent the truncation of zero second fields SimpleModule rfc3339Module = new SimpleModule("rfc3339Module"); rfc3339Module.addSerializer(new Rfc3339OffsetDateTimeSerializer(OffsetDateTime.class)); objectMapper.registerModule(rfc3339Module); return objectMapper; }