Java Code Examples for com.fasterxml.jackson.dataformat.xml.XmlMapper#registerModule()
The following examples show how to use
com.fasterxml.jackson.dataformat.xml.XmlMapper#registerModule() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApiClient.java From openapi-generator with Apache License 2.0 | 6 votes |
/** * Build the RestTemplate used to make HTTP requests. * @return RestTemplate */ protected RestTemplate buildRestTemplate() { List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>(); messageConverters.add(new MappingJackson2HttpMessageConverter()); XmlMapper xmlMapper = new XmlMapper(); xmlMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true); xmlMapper.registerModule(new JsonNullableModule()); messageConverters.add(new MappingJackson2XmlHttpMessageConverter(xmlMapper)); RestTemplate restTemplate = new RestTemplate(messageConverters); for(HttpMessageConverter converter:restTemplate.getMessageConverters()){ if(converter instanceof AbstractJackson2HttpMessageConverter){ ObjectMapper mapper = ((AbstractJackson2HttpMessageConverter)converter).getObjectMapper(); ThreeTenModule module = new ThreeTenModule(); module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT); module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME); module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME); mapper.registerModule(module); mapper.registerModule(new JsonNullableModule()); } } // This allows us to read the response more than once - Necessary for debugging. restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(restTemplate.getRequestFactory())); return restTemplate; }
Example 2
Source File: EmailAttachmentFileCreator.java From blackduck-alert with Apache License 2.0 | 5 votes |
private File createXmlFile(MessageContentGroup messageContentGroup, File writeDir) throws IOException { XmlMapper xmlMapper = new XmlMapper(); xmlMapper.registerModule(new Jdk8Module()); String xmlMessage = xmlMapper.writeValueAsString(messageContentGroup); return createFile(xmlMessage, writeDir, "xml"); }
Example 3
Source File: JacksonXML.java From dropwizard-xml with Apache License 2.0 | 5 votes |
/** * Creates a new {@link com.fasterxml.jackson.dataformat.xml.XmlMapper} using Woodstox * with Logback and Joda Time support. * Also includes all {@link io.dropwizard.jackson.Discoverable} interface implementations. * * @return XmlMapper */ public static XmlMapper newXMLMapper(JacksonXmlModule jacksonXmlModule) { final XmlFactory woodstoxFactory = new XmlFactory(new WstxInputFactory(), new WstxOutputFactory()); final XmlMapper mapper = new XmlMapper(woodstoxFactory, jacksonXmlModule); mapper.registerModule(new GuavaModule()); mapper.registerModule(new GuavaExtrasModule()); mapper.registerModule(new JodaModule()); mapper.registerModule(new FuzzyEnumModule()); mapper.setPropertyNamingStrategy(new AnnotationSensitivePropertyNamingStrategy()); mapper.setSubtypeResolver(new DiscoverableSubtypeResolver()); return mapper; }
Example 4
Source File: XML.java From rapidoid with Apache License 2.0 | 5 votes |
public static XmlMapper newMapper() { XmlMapper mapper = new XmlMapper(); mapper.setBase64Variant(Base64Variants.MODIFIED_FOR_URL); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); if (!Env.dev()) { mapper.registerModule(new AfterburnerModule()); } return mapper; }
Example 5
Source File: JacksonPrinterTest.java From eclair with Apache License 2.0 | 4 votes |
@Before public void init() { xmlMapper = new XmlMapper(); xmlMapper.registerModule(new JaxbAnnotationModule()); }
Example 6
Source File: AssignmentConversionServiceImpl.java From sakai with Educational Community License v2.0 | 4 votes |
@Override public void runConversion(int numberOfAttributes, int lengthOfAttribute) { int assignmentsTotal, progress = 0; assignmentsConverted = submissionsConverted = submissionsFailed = assignmentsFailed = 0; SimpleModule module = new SimpleModule().addDeserializer(String.class, new StdDeserializer<String>(String.class) { @Override public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { String str = StringDeserializer.instance.deserialize(p, ctxt); if (StringUtils.isBlank(str)) return null; return str; } }); // woodstox xml parser defaults we don't allow values smaller than the default if (numberOfAttributes < ReaderConfig.DEFAULT_MAX_ATTRIBUTES_PER_ELEMENT) numberOfAttributes = ReaderConfig.DEFAULT_MAX_ATTRIBUTES_PER_ELEMENT; if (lengthOfAttribute < ReaderConfig.DEFAULT_MAX_ATTRIBUTE_LENGTH) lengthOfAttribute = ReaderConfig.DEFAULT_MAX_ATTRIBUTE_LENGTH; log.info("<===== Assignments conversion xml parser limits: number of attributes={}, attribute size={} =====>", numberOfAttributes, lengthOfAttribute); XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory(); xmlInputFactory.setProperty(WstxInputProperties.P_MAX_ATTRIBUTES_PER_ELEMENT, numberOfAttributes); xmlInputFactory.setProperty(WstxInputProperties.P_MAX_ATTRIBUTE_SIZE, lengthOfAttribute); xmlMapper = new XmlMapper(xmlInputFactory); xmlMapper.registerModule(new Jdk8Module()); xmlMapper.registerModule(module); String configValue = "org.sakaiproject.assignment.api.model.Assignment,org.sakaiproject.assignment.api.model.AssignmentSubmission"; String currentValue = serverConfigurationService.getConfig(AssignableUUIDGenerator.HIBERNATE_ASSIGNABLE_ID_CLASSES, null); if (StringUtils.isNotBlank(currentValue)) { configValue = configValue + "," + currentValue; } ServerConfigurationService.ConfigItem configItem = BasicConfigItem.makeConfigItem( AssignableUUIDGenerator.HIBERNATE_ASSIGNABLE_ID_CLASSES, configValue, AssignmentConversionServiceImpl.class.getName(), true); serverConfigurationService.registerConfigItem(configItem); List<String> preAssignments = dataProvider.fetchAssignmentsToConvert(); List<String> postAssignments = assignmentRepository.findAllAssignmentIds(); List<String> convertAssignments = new ArrayList<>(preAssignments); convertAssignments.removeAll(postAssignments); assignmentsTotal = convertAssignments.size(); log.info("<===== Assignments pre 12 [{}] and post 12 [{}] to convert {} =====>", preAssignments.size(), postAssignments.size(), assignmentsTotal); for (String assignmentId : convertAssignments) { try { convert(assignmentId); } catch (Exception e) { log.warn("Assignment conversion exception for {}", assignmentId, e); } int percent = new Double(((assignmentsConverted + assignmentsFailed) / (double) assignmentsTotal) * 100).intValue(); if (progress != percent) { progress = percent; log.info("<===== Assignments conversion completed {}% =====>", percent); } } configItem = BasicConfigItem.makeConfigItem( AssignableUUIDGenerator.HIBERNATE_ASSIGNABLE_ID_CLASSES, StringUtils.trimToEmpty(currentValue), AssignmentConversionServiceImpl.class.getName()); serverConfigurationService.registerConfigItem(configItem); log.info("<===== Assignments converted {} =====>", assignmentsConverted); log.info("<===== Submissions converted {} =====>", submissionsConverted); log.info("<===== Assignments that failed to be converted {} =====>", assignmentsFailed); log.info("<===== Submissions that failed to be converted {} =====>", submissionsFailed); }
Example 7
Source File: BaseTest.java From vavr-jackson with Apache License 2.0 | 4 votes |
public XmlMapper xmlMapperJaxb() { XmlMapper xmlMapper = new XmlMapper(); xmlMapper.registerModule(new JaxbAnnotationModule()); xmlMapper.registerModule(new VavrModule()); return xmlMapper; }
Example 8
Source File: AssignmentConversionServiceImpl.java From sakai with Educational Community License v2.0 | 4 votes |
@Override public void runConversion(int numberOfAttributes, int lengthOfAttribute) { int assignmentsTotal, progress = 0; assignmentsConverted = submissionsConverted = submissionsFailed = assignmentsFailed = 0; SimpleModule module = new SimpleModule().addDeserializer(String.class, new StdDeserializer<String>(String.class) { @Override public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { String str = StringDeserializer.instance.deserialize(p, ctxt); if (StringUtils.isBlank(str)) return null; return str; } }); // woodstox xml parser defaults we don't allow values smaller than the default if (numberOfAttributes < ReaderConfig.DEFAULT_MAX_ATTRIBUTES_PER_ELEMENT) numberOfAttributes = ReaderConfig.DEFAULT_MAX_ATTRIBUTES_PER_ELEMENT; if (lengthOfAttribute < ReaderConfig.DEFAULT_MAX_ATTRIBUTE_LENGTH) lengthOfAttribute = ReaderConfig.DEFAULT_MAX_ATTRIBUTE_LENGTH; log.info("<===== Assignments conversion xml parser limits: number of attributes={}, attribute size={} =====>", numberOfAttributes, lengthOfAttribute); XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory(); xmlInputFactory.setProperty(WstxInputProperties.P_MAX_ATTRIBUTES_PER_ELEMENT, numberOfAttributes); xmlInputFactory.setProperty(WstxInputProperties.P_MAX_ATTRIBUTE_SIZE, lengthOfAttribute); xmlMapper = new XmlMapper(xmlInputFactory); xmlMapper.registerModule(new Jdk8Module()); xmlMapper.registerModule(module); String configValue = "org.sakaiproject.assignment.api.model.Assignment,org.sakaiproject.assignment.api.model.AssignmentSubmission"; String currentValue = serverConfigurationService.getConfig(AssignableUUIDGenerator.HIBERNATE_ASSIGNABLE_ID_CLASSES, null); if (StringUtils.isNotBlank(currentValue)) { configValue = configValue + "," + currentValue; } ServerConfigurationService.ConfigItem configItem = BasicConfigItem.makeConfigItem( AssignableUUIDGenerator.HIBERNATE_ASSIGNABLE_ID_CLASSES, configValue, AssignmentConversionServiceImpl.class.getName(), true); serverConfigurationService.registerConfigItem(configItem); List<String> preAssignments = dataProvider.fetchAssignmentsToConvert(); List<String> postAssignments = assignmentRepository.findAllAssignmentIds(); List<String> convertAssignments = new ArrayList<>(preAssignments); convertAssignments.removeAll(postAssignments); assignmentsTotal = convertAssignments.size(); log.info("<===== Assignments pre 12 [{}] and post 12 [{}] to convert {} =====>", preAssignments.size(), postAssignments.size(), assignmentsTotal); for (String assignmentId : convertAssignments) { try { convert(assignmentId); } catch (Exception e) { log.warn("Assignment conversion exception for {}", assignmentId, e); } int percent = new Double(((assignmentsConverted + assignmentsFailed) / (double) assignmentsTotal) * 100).intValue(); if (progress != percent) { progress = percent; log.info("<===== Assignments conversion completed {}% =====>", percent); } } configItem = BasicConfigItem.makeConfigItem( AssignableUUIDGenerator.HIBERNATE_ASSIGNABLE_ID_CLASSES, StringUtils.trimToEmpty(currentValue), AssignmentConversionServiceImpl.class.getName()); serverConfigurationService.registerConfigItem(configItem); log.info("<===== Assignments converted {} =====>", assignmentsConverted); log.info("<===== Submissions converted {} =====>", submissionsConverted); log.info("<===== Assignments that failed to be converted {} =====>", assignmentsFailed); log.info("<===== Submissions that failed to be converted {} =====>", submissionsFailed); }