public ObjectMapper create(boolean defaultUseWrapper) { JacksonXmlModule module = new JacksonXmlModule(); module.setDefaultUseWrapper(defaultUseWrapper); return new XmlMapper(new XmlFactory(StaxUtils.createDefensiveInputFactory()), module); } }
public static <T> T readValue(File src, Class<T> valueType) throws IOException { return xmlMapper.readValue(src, valueType); }
@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. module.setDefaultUseWrapper(false); XmlMapper xmlMapper = new XmlMapper(module); xmlMapper.registerModule(new AfterburnerModule()); return xmlMapper; }
public ObjectMapper create() { return new XmlMapper(StaxUtils.createDefensiveInputFactory()); }
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; }
public EurekaXmlJacksonCodec(final KeyFormatter keyFormatter, boolean compact) { xmlMapper = new XmlMapper() { public ObjectMapper registerModule(Module module) { setSerializerFactory( getSerializerFactory().withSerializerModifier(EurekaJacksonXmlModifiers.createXmlSerializerModifier(keyFormatter)) ); return super.registerModule(module); } }; xmlMapper.setSerializationInclusion(Include.NON_NULL); xmlMapper.addMixIn(DataCenterInfo.class, DataCenterInfoXmlMixIn.class); xmlMapper.addMixIn(InstanceInfo.PortWrapper.class, PortWrapperXmlMixIn.class); xmlMapper.addMixIn(Application.class, ApplicationXmlMixIn.class); xmlMapper.addMixIn(Applications.class, ApplicationsXmlMixIn.class); SimpleModule xmlModule = new SimpleModule(); xmlMapper.registerModule(xmlModule); if (compact) { addMiniConfig(xmlMapper); } }
public static void stringify(Object value, ReusableWritable out) { XmlMapper mapper = newMapper(); try { mapper.writeValue(out, value); } catch (IOException ex) { throw new RuntimeException(ex); } }
public ObjectMapper registerModule(Module module) { setSerializerFactory( getSerializerFactory().withSerializerModifier(EurekaJacksonXmlModifiers.createXmlSerializerModifier(keyFormatter)) ); return super.registerModule(module); } };
public ObjectMapper create(boolean defaultUseWrapper) { JacksonXmlModule module = new JacksonXmlModule(); module.setDefaultUseWrapper(defaultUseWrapper); return new XmlMapper(new XmlFactory(StaxUtils.createDefensiveInputFactory()), module); } }
public ObjectMapper create() { return new XmlMapper(StaxUtils.createDefensiveInputFactory()); }
public static <T> T readValue(String content, Class<T> valueType) throws IOException { return xmlMapper.readValue(content, valueType); }
public static String stringify(Object obj) { XmlMapper mapper = newMapper(); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { mapper.writeValue(out, obj); } catch (IOException ex) { throw new RuntimeException(ex); } return out.toString(); }
@Test public void setObjectMapper() { this.factory.setObjectMapper(new XmlMapper()); this.factory.afterPropertiesSet(); assertNotNull(this.factory.getObject()); assertTrue(this.factory.isSingleton()); assertEquals(XmlMapper.class, this.factory.getObjectType()); }
public static <T> T readValue(InputStream inputStream, Class<T> valueType) throws IOException { return xmlMapper.readValue(inputStream, valueType); }
@Override public void render(Req req, Object value, OutputStream out) throws Exception { Customization.of(req).xmlMapper().writeValue(out, value); }
@SuppressWarnings("unchecked") public static <T> T parse(byte[] xml, Class<T> valueType) { try { XmlMapper mapper = newMapper(); return mapper.readValue(xml, valueType); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public void invoke(Context context, Result result) { ResponseStreams responseStreams = context.finalizeHeaders(result); try (OutputStream outputStream = responseStreams.getOutputStream()) { xmlMapper.writeValue(outputStream, result.getRenderable()); } catch (IOException e) { logger.error("Error while rendering json", e); } }
@SuppressWarnings("unchecked") @Override public Map<String, ?> parseRequestBody(Req req, byte[] body) throws Exception { return Customization.of(req).xmlMapper().readValue(body, Map.class); }
public <T> T invoke(Context context, Class<T> classOfT) { try { return xmlMapper.readValue(context.getInputStream(), classOfT); } catch (JsonParseException | JsonMappingException e) { throw new BadRequestException("Error parsing incoming Xml", e); } catch (IOException e) { throw new BadRequestException("Invalid Xml document", e); } }