List of usage examples for com.fasterxml.jackson.databind ObjectMapper writeValueAsBytes
@SuppressWarnings("resource") public byte[] writeValueAsBytes(Object value) throws JsonProcessingException
From source file:com.couchbase.lite.support.JsonDocumentTest.java
public void testDoubleFragment() throws Exception { Double fragment = 3.5;// w w w . j a va 2 s . co m ObjectMapper mapper = new ObjectMapper(); byte[] json = mapper.writeValueAsBytes(fragment); JsonDocument jsdoc = new JsonDocument(json); assertEquals(fragment, jsdoc.jsonObject()); }
From source file:com.couchbase.lite.support.JsonDocumentTest.java
public void testDateFragment() throws Exception { Date fragment = new Date(); ObjectMapper mapper = new ObjectMapper(); byte[] json = mapper.writeValueAsBytes(fragment); JsonDocument jsdoc = new JsonDocument(json); assertEquals(fragment, new Date((Long) jsdoc.jsonObject())); }
From source file:org.saltyrtc.client.messages.c2c.Application.java
@Override public void write(MessagePacker packer) throws IOException { packer.packMapHeader(2).packString("type").packString(TYPE).packString("data"); ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory()); packer.writePayload(objectMapper.writeValueAsBytes(this.data)); }
From source file:com.couchbase.lite.support.JsonDocumentTest.java
public void testJsonObject() throws Exception { Map<String, Object> dict = new HashMap<String, Object>(); dict.put("id", "01234567890"); dict.put("foo", "bar"); dict.put("int", 5); dict.put("double", 3.5); dict.put("bool", true); dict.put("date", new Date().toString()); ObjectMapper mapper = new ObjectMapper(); byte[] json = mapper.writeValueAsBytes(dict); JsonDocument jsdoc = new JsonDocument(json); assertEquals(dict, jsdoc.jsonObject()); }
From source file:com.couchbase.lite.support.JsonDocumentTest.java
public void testJsonArray() throws Exception { List<Object> array = new ArrayList<Object>(); array.add("01234567890"); array.add("bar"); array.add(5);/*from www. j av a2 s. c o m*/ array.add(3.5); array.add(true); array.add(new Date().toString()); ObjectMapper mapper = new ObjectMapper(); byte[] json = mapper.writeValueAsBytes(array); JsonDocument jsdoc = new JsonDocument(json); assertEquals(array, jsdoc.jsonObject()); }
From source file:io.github.autsia.crowly.tests.IntegrationTestingUtils.java
public byte[] convertObjectToJsonBytes(Object object) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); return mapper.writeValueAsBytes(object); }
From source file:net.nullschool.grains.jackson.datatype.BasicCollectionsTest.java
@Test public void test_basicConstList() throws IOException { ConstList<Integer> list = emptyList(); for (int i = 0; i < 10; i++) { ObjectMapper mapper = newGrainsObjectMapper(); byte[] data = mapper.writeValueAsBytes(list); ConstList<?> actual = mapper.readValue(data, ConstList.class); CollectionTestingTools.compare_lists(list, actual); list = list.with(i);/*ww w. j a v a 2 s.c o m*/ } }
From source file:net.nullschool.grains.jackson.datatype.BasicCollectionsTest.java
@Test public void test_basicConstSet() throws IOException { ConstSet<Integer> set = emptySet(); for (int i = 0; i < 10; i++) { ObjectMapper mapper = newGrainsObjectMapper(); byte[] data = mapper.writeValueAsBytes(set); ConstSet<?> actual = mapper.readValue(data, ConstSet.class); CollectionTestingTools.compare_sets(set, actual); set = set.with(i);// w w w. ja v a 2 s . c o m } }
From source file:net.nullschool.grains.jackson.datatype.BasicCollectionsTest.java
@Test public void test_basicConstMap() throws IOException { ConstMap<String, Integer> map = emptyMap(); for (int i = 0; i < 10; i++) { ObjectMapper mapper = newGrainsObjectMapper(); byte[] data = mapper.writeValueAsBytes(map); ConstMap<?, ?> actual = mapper.readValue(data, ConstMap.class); CollectionTestingTools.compare_maps(map, actual); map = map.with(String.valueOf(i), i); }// w w w .ja va2 s. c o m }
From source file:net.nullschool.grains.jackson.datatype.BasicCollectionsTest.java
@Test public void test_basicConstSortedSet() throws IOException { ConstSortedSet<Integer> set = emptySortedSet(null); for (int i = 0; i < 10; i++) { ObjectMapper mapper = newGrainsObjectMapper(); byte[] data = mapper.writeValueAsBytes(set); ConstSortedSet<?> actual = mapper.readValue(data, new TypeReference<ConstSortedSet<Integer>>() { });// ww w . j av a 2 s . c o m CollectionTestingTools.compare_sorted_sets(set, actual); set = set.with(i); } }