List of usage examples for com.fasterxml.jackson.dataformat.yaml YAMLFactory configure
public final YAMLFactory configure(YAMLGenerator.Feature f, boolean state)
From source file:org.restlet.ext.jackson.JacksonRepresentation.java
/** * Creates a Jackson object mapper based on a media type. It supports JSON, * JSON Smile, XML, YAML and CSV./*from www . j av a 2s . c o m*/ * * @return The Jackson object mapper. */ protected ObjectMapper createObjectMapper() { ObjectMapper result = null; if (MediaType.APPLICATION_JSON.isCompatible(getMediaType())) { JsonFactory jsonFactory = new JsonFactory(); jsonFactory.configure(Feature.AUTO_CLOSE_TARGET, false); result = new ObjectMapper(jsonFactory); } else if (MediaType.APPLICATION_JSON_SMILE.isCompatible(getMediaType())) { SmileFactory smileFactory = new SmileFactory(); smileFactory.configure(Feature.AUTO_CLOSE_TARGET, false); result = new ObjectMapper(smileFactory); // [ifndef android] } else if (MediaType.APPLICATION_XML.isCompatible(getMediaType()) || MediaType.TEXT_XML.isCompatible(getMediaType())) { javax.xml.stream.XMLInputFactory xif = XmlFactoryProvider.newInputFactory(); xif.setProperty(javax.xml.stream.XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, isExpandingEntityRefs()); xif.setProperty(javax.xml.stream.XMLInputFactory.SUPPORT_DTD, isExpandingEntityRefs()); xif.setProperty(javax.xml.stream.XMLInputFactory.IS_VALIDATING, isValidatingDtd()); javax.xml.stream.XMLOutputFactory xof = XmlFactoryProvider.newOutputFactory(); XmlFactory xmlFactory = new XmlFactory(xif, xof); xmlFactory.configure(Feature.AUTO_CLOSE_TARGET, false); result = new XmlMapper(xmlFactory); // [enddef] } else if (MediaType.APPLICATION_YAML.isCompatible(getMediaType()) || MediaType.TEXT_YAML.isCompatible(getMediaType())) { YAMLFactory yamlFactory = new YAMLFactory(); yamlFactory.configure(Feature.AUTO_CLOSE_TARGET, false); result = new ObjectMapper(yamlFactory); } else if (MediaType.TEXT_CSV.isCompatible(getMediaType())) { CsvFactory csvFactory = new CsvFactory(); csvFactory.configure(Feature.AUTO_CLOSE_TARGET, false); result = new CsvMapper(csvFactory); } else { JsonFactory jsonFactory = new JsonFactory(); jsonFactory.configure(Feature.AUTO_CLOSE_TARGET, false); result = new ObjectMapper(jsonFactory); } return result; }