@Test public void testEncodeAndDecodeRegisterSerializerDirectlyToModule() { JsonObjectMapper mapper = new JsonObjectMapper(); SimpleModule module = new SimpleModule("cemo", Version.unknownVersion()); module.addSerializer(Point.class, new PointSerializer()); mapper.registerModule(module); transcoder = new JsonTranscoder(mapper); Point p = new Point(40, 50); CachedObject co = transcoder.encode(p); assertNotNull(co); assertNotNull(co.getData()); assertEquals("{\"v\":\"40x50\"}", new String(co.getData())); }
@Override public CachedObject encode(final Object o) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { mapper.writeValue(baos, new Holder(o)); return new CachedObjectImpl(JSON_SERIALIZED, baos.toByteArray()); } catch (IOException e) { LOGGER.warn(String.format("Error serializing object %s", o), e); throw new RuntimeException(e); } finally { try { baos.close(); } catch (IOException e) { LOGGER.warn("Error while closing stream", e); } } }
JsonTranscoder implements CacheTranscoder { @Override public CachedObject encode(final Object o) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { mapper.writeValue(baos, new Holder(o)); return new CachedObjectImpl(JSON_SERIALIZED, baos.toByteArray()); } catch (IOException e) { LOGGER.warn(String.format("Error serializing object %s", o), e); throw new RuntimeException(e); } finally { try { baos.close(); } catch (IOException e) { LOGGER.warn("Error while closing stream", e); } } } }
JsonTranscoder implements CacheTranscoder { @Override public CachedObject encode(final Object o) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { mapper.writeValue(baos, new Holder(o)); return new CachedObjectImpl(JSON_SERIALIZED, baos.toByteArray()); } catch (IOException e) { LOGGER.warn(String.format("Error serializing object %s", o), e); throw new RuntimeException(e); } finally { try { baos.close(); } catch (IOException e) { LOGGER.warn("Error while closing stream", e); } } } JsonTranscoder(final ObjectMapper mapper); }
JsonTranscoder implements CacheTranscoder { @Override public CachedObject encode(final Object o) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { mapper.writeValue(baos, new Holder(o)); return new CachedObjectImpl(JSON_SERIALIZED, baos.toByteArray()); } catch (IOException e) { LOGGER.warn(String.format("Error serializing object %s", o), e); throw new RuntimeException(e); } finally { try { baos.close(); } catch (IOException e) { LOGGER.warn("Error while closing stream", e); } } } JsonTranscoder(final ObjectMapper mapper); boolean asyncDecode(final CachedObject data); @Override Object decode(final CachedObject data); @Override CachedObject encode(final Object o); int getMaxSize(); }
JsonTranscoder implements CacheTranscoder { @Override public CachedObject encode(final Object o) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { mapper.writeValue(baos, new Holder(o)); return new CachedObjectImpl(JSON_SERIALIZED, baos.toByteArray()); } catch (IOException e) { LOGGER.warn(String.format("Error serializing object %s", o), e); throw new RuntimeException(e); } finally { try { baos.close(); } catch (IOException e) { LOGGER.warn("Error while closing stream", e); } } } JsonTranscoder(final ObjectMapper mapper); boolean asyncDecode(final CachedObject data); @Override Object decode(final CachedObject data); @Override CachedObject encode(final Object o); int getMaxSize();  }