List of usage examples for com.fasterxml.jackson.dataformat.xml XmlMapper registerModule
public ObjectMapper registerModule(Module module)
From source file:com.ning.billing.recurly.model.RecurlyObject.java
public static XmlMapper newXmlMapper() { final XmlMapper xmlMapper = new XmlMapper(); xmlMapper.setSerializerProvider(new RecurlyXmlSerializerProvider()); final AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); final AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()); final AnnotationIntrospector pair = new AnnotationIntrospectorPair(primary, secondary); xmlMapper.setAnnotationIntrospector(pair); xmlMapper.registerModule(new JodaModule()); xmlMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); final SimpleModule m = new SimpleModule("module", new Version(1, 0, 0, null, null, null)); m.addSerializer(Accounts.class, new RecurlyObjectsSerializer<Accounts, Account>(Accounts.class, "account")); m.addSerializer(AddOns.class, new RecurlyObjectsSerializer<AddOns, AddOn>(AddOns.class, "add_on")); m.addSerializer(Adjustments.class, new RecurlyObjectsSerializer<Adjustments, Adjustment>(Adjustments.class, "adjustment")); m.addSerializer(Coupons.class, new RecurlyObjectsSerializer<Coupons, Coupon>(Coupons.class, "coupon")); m.addSerializer(Invoices.class, new RecurlyObjectsSerializer<Invoices, Invoice>(Invoices.class, "invoice")); m.addSerializer(Plans.class, new RecurlyObjectsSerializer<Plans, Plan>(Plans.class, "plan")); m.addSerializer(RecurlyErrors.class, new RecurlyObjectsSerializer<RecurlyErrors, RecurlyError>(RecurlyErrors.class, "error")); m.addSerializer(SubscriptionAddOns.class, new RecurlyObjectsSerializer<SubscriptionAddOns, SubscriptionAddOn>(SubscriptionAddOns.class, "subscription_add_on")); m.addSerializer(Subscriptions.class, new RecurlyObjectsSerializer<Subscriptions, Subscription>(Subscriptions.class, "subscription")); m.addSerializer(Transactions.class, new RecurlyObjectsSerializer<Transactions, Transaction>(Transactions.class, "transaction")); xmlMapper.registerModule(m);// w ww .ja va 2 s .c o m return xmlMapper; }
From source file:ninja.utils.XmlMapperProvider.java
@Override public XmlMapper get() { JacksonXmlModule module = new JacksonXmlModule(); // Check out: https://github.com/FasterXML/jackson-dataformat-xml // setDefaultUseWrapper produces more similar output to // the Json output. You can change that with annotations in your // models.//from w w w .ja v a 2 s. c om module.setDefaultUseWrapper(false); XmlMapper xmlMapper = new XmlMapper(module); xmlMapper.registerModule(new AfterburnerModule()); return xmlMapper; }
From source file:com.programmingskillz.SampleApplication.java
private JacksonXMLProvider jacksonXMLProvider() { XmlMapper xmlMapper = new XmlMapper(); xmlMapper.registerModule(new JavaTimeModule()); JacksonXMLProvider xmlProvider = new JacksonXMLProvider(); xmlProvider.setMapper(xmlMapper);// w w w. j a va 2 s . co m xmlProvider.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); return xmlProvider; }
From source file:com.ning.billing.recurly.model.TestXmlMapper.java
@Test(groups = "fast", description = "See https://github.com/FasterXML/jackson-dataformat-xml/issues/76") public void testCollection() throws Exception { final XmlMapper xmlMapper = new XmlMapper(); xmlMapper.setSerializerProvider(new RecurlyXmlSerializerProvider()); final SimpleModule m = new SimpleModule("module", new Version(1, 0, 0, null, null, null)); m.addSerializer(Values.class, new ValuesSerializer()); xmlMapper.registerModule(m); final Values values = xmlMapper .readValue(//from w w w .ja v a 2s .c o m "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + " <values type=\"array\">\n" + " <value>Hi!</value>" + " <value>Salut!</value>" + " </values>", Values.class); Assert.assertEquals(values.size(), 2, values.toString()); Assert.assertEquals(values.get(0), "Hi!"); Assert.assertEquals(values.get(1), "Salut!"); // Test we can re-serialize final String valueAsString = xmlMapper.writeValueAsString(values); final Values values2 = xmlMapper.readValue(valueAsString, Values.class); Assert.assertEquals(values2, values, valueAsString); }