List of usage examples for com.fasterxml.jackson.dataformat.smile SmileFactory configure
public final SmileFactory configure(SmileGenerator.Feature f, boolean state)
From source file:com.raythos.sentilexo.persistence.cql.PersistedEntity.java
public static byte[] toBinaryJSon(PersistedEntity item) { try {//from www . j a v a2 s . c o m SmileFactory f = new SmileFactory(); f.configure(SmileParser.Feature.REQUIRE_HEADER, true); ObjectMapper mapper = new ObjectMapper(f); mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); byte[] result = mapper.writeValueAsBytes(item); return result; } catch (JsonProcessingException ex) { Logger.getLogger(QueryResultItemMapper.class.getName()).log(Level.SEVERE, null, ex); return null; } }
From source file:com.raythos.sentilexo.persistence.cql.PersistedEntity.java
public static PersistedEntity fromBinaryJSon(byte[] data, Class classType) { try {//ww w . j av a2 s. c o m SmileFactory f = new SmileFactory(); f.configure(SmileParser.Feature.REQUIRE_HEADER, true); ObjectMapper mapper = new ObjectMapper(f); mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); Object result = mapper.readValue(data, classType); return (PersistedEntity) result; } catch (IOException ex) { Logger.getLogger(PersistedEntity.class.getName()).log(Level.SEVERE, null, ex); return null; } }
From source file:com.ning.metrics.serialization.event.TestSmileEnvelopeEvent.java
@BeforeTest public void setUp() throws IOException { // Use same configuration as SmileEnvelopeEvent final SmileFactory f = new SmileFactory(); f.configure(SmileGenerator.Feature.CHECK_SHARED_NAMES, true); f.configure(SmileGenerator.Feature.CHECK_SHARED_STRING_VALUES, true); f.configure(SmileParser.Feature.REQUIRE_HEADER, false); final ByteArrayOutputStream stream = new ByteArrayOutputStream(); final JsonGenerator g = f.createJsonGenerator(stream); g.writeStartObject();// w w w. jav a 2 s . co m g.writeStringField(SmileEnvelopeEvent.SMILE_EVENT_GRANULARITY_TOKEN_NAME, eventGranularity.toString()); g.writeObjectFieldStart("name"); g.writeStringField("first", "Joe"); g.writeStringField("last", "Sixpack"); g.writeEndObject(); // for field 'name' g.writeStringField("gender", "MALE"); g.writeNumberField(SmileEnvelopeEvent.SMILE_EVENT_DATETIME_TOKEN_NAME, eventDateTime.getMillis()); g.writeBooleanField("verified", false); g.writeEndObject(); g.close(); // important: will force flushing of output, close underlying output stream serializedBytes = stream.toByteArray(); // one sanity check; should be able to round-trip via String (iff using latin-1!) serializedString = stream.toString(SmileEnvelopeEvent.CHARSET.toString()); }
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 w ww. j av a2 s .co 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; }