@Test public void toStringTest() { Message[] messages = new Message[]{ new CheckpointMessage("1234567890", 0L, null), new InitializeMessage(InitializationInput.builder().shardId("shard-123").build()), new ProcessRecordsMessage(ProcessRecordsInput.builder() .records(Collections.singletonList( KinesisClientRecord.builder() .data(ByteBuffer.wrap("cat".getBytes())) .partitionKey("cat") .sequenceNumber("555") .build())) .build()), new ShutdownMessage(ShutdownReason.LEASE_LOST), new StatusMessage("processRecords"), new InitializeMessage(), new ProcessRecordsMessage(), new ShutdownRequestedMessage(), new LeaseLostMessage(), new ShardEndedMessage() }; for (int i = 0; i < messages.length; i++) { System.out.println(messages[i].toString()); Assert.assertTrue("Each message should contain the action field", messages[i].toString().contains("action")); } KinesisClientRecord defaultJsonFriendlyRecord = KinesisClientRecord.builder().build(); Assert.assertNull(defaultJsonFriendlyRecord.partitionKey()); Assert.assertNull(defaultJsonFriendlyRecord.data()); Assert.assertNull(defaultJsonFriendlyRecord.sequenceNumber()); Assert.assertNull(new ShutdownMessage(null).getReason()); Message withBadMapper = new Message() { }.withObjectMapper(new ObjectMapper() { private static final long serialVersionUID = 1L; @Override public String writeValueAsString(Object m) throws JsonProcessingException { throw new JsonProcessingException(new Throwable()) { }; } }); String s = withBadMapper.toString(); Assert.assertNotNull(s); }
public String toString() { try { return mapper.writeValueAsString(this); } catch (Exception e) { return super.toString(); } }
Message { public String toString() { try { return mapper.writeValueAsString(this); } catch (Exception e) { return super.toString(); } } }
Message { public String toString() { try { return mapper.writeValueAsString(this); } catch (Exception e) { return super.toString(); } } Message(); }
Message { public String toString() { try { return mapper.writeValueAsString(this); } catch (Exception e) { return super.toString(); } } Message(); String toString(); }
Message { public String toString() { try { return mapper.writeValueAsString(this); } catch (Exception e) { return super.toString(); } } Message(); String toString();  }