@Test public void testInvalidSerialize() { Gson gson = PowerMock.createMock(Gson.class); gson.toJson(EasyMock.isA(Object.class), EasyMock.isA(Appendable.class)); EasyMock.expectLastCall().andThrow(new JsonIOException("error")); PowerMock.replay(gson); ServiceInstance instance = new ServiceInstance(new Endpoint("foo", 1000), ImmutableMap.of(), Status.ALIVE); try { new JsonCodec(gson).serialize(instance, new ByteArrayOutputStream()); fail(); } catch (IOException e) { } PowerMock.verify(gson); }
@Override public void serialize(ServiceInstance instance, OutputStream sink) throws IOException { Writer writer = new OutputStreamWriter(sink, ENCODING); try { gson.toJson(new ServiceInstanceSchema(instance), writer); } catch (JsonIOException e) { throw new IOException(String.format("Problem serializing %s to JSON", instance), e); } writer.flush(); }
JsonCodec implements Codec<ServiceInstance> { @Override public void serialize(ServiceInstance instance, OutputStream sink) throws IOException { Writer writer = new OutputStreamWriter(sink, ENCODING); try { gson.toJson(new ServiceInstanceSchema(instance), writer); } catch (JsonIOException e) { throw new IOException(String.format("Problem serializing %s to JSON", instance), e); } writer.flush(); } }
JsonCodec implements Codec<ServiceInstance> { @Override public void serialize(ServiceInstance instance, OutputStream sink) throws IOException { Writer writer = new OutputStreamWriter(sink, ENCODING); try { gson.toJson(new ServiceInstanceSchema(instance), writer); } catch (JsonIOException e) { throw new IOException(String.format("Problem serializing %s to JSON", instance), e); } writer.flush(); } JsonCodec();   JsonCodec(Gson gson); }
JsonCodec implements Codec<ServiceInstance> { @Override public void serialize(ServiceInstance instance, OutputStream sink) throws IOException { Writer writer = new OutputStreamWriter(sink, ENCODING); try { gson.toJson(new ServiceInstanceSchema(instance), writer); } catch (JsonIOException e) { throw new IOException(String.format("Problem serializing %s to JSON", instance), e); } writer.flush(); } JsonCodec();   JsonCodec(Gson gson); @Override void serialize(ServiceInstance instance, OutputStream sink); @Override ServiceInstance deserialize(InputStream source); }
JsonCodec implements Codec<ServiceInstance> { @Override public void serialize(ServiceInstance instance, OutputStream sink) throws IOException { Writer writer = new OutputStreamWriter(sink, ENCODING); try { gson.toJson(new ServiceInstanceSchema(instance), writer); } catch (JsonIOException e) { throw new IOException(String.format("Problem serializing %s to JSON", instance), e); } writer.flush(); } JsonCodec();   JsonCodec(Gson gson); @Override void serialize(ServiceInstance instance, OutputStream sink); @Override ServiceInstance deserialize(InputStream source);  }