### Question:
SingleMotorVibrateCmd extends ButtplugDeviceMessage { public double getSpeed() { if (speed > 1 || speed < 0) { return 0; } return speed; } SingleMotorVibrateCmd(long deviceIndex, double speed, long id);  SingleMotorVibrateCmd(double speed); @SuppressWarnings("unused") private  SingleMotorVibrateCmd(); double getSpeed(); void setSpeed(double speed);  }### Answer:
@Test public void test() throws IOException { String testStr = "[\n" + " {\n" + " \"SingleMotorVibrateCmd\": {\n" + " \"Id\": 1,\n" + " \"DeviceIndex\": 0,\n" + " \"Speed\": 0.5\n" + " }\n" + " }\n" + "]"; ButtplugJsonMessageParser parser = new ButtplugJsonMessageParser(); List<ButtplugMessage> msgs = parser.deserialize(testStr); Assert.assertEquals(1, msgs.size()); Assert.assertEquals(SingleMotorVibrateCmd.class, msgs.get(0).getClass()); Assert.assertEquals(1, msgs.get(0).id); Assert.assertEquals(0, ((SingleMotorVibrateCmd) msgs.get(0)).deviceIndex); Assert.assertEquals(0.5, ((SingleMotorVibrateCmd) msgs.get(0)).getSpeed(), 0); ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonNode = objectMapper.readValue(testStr, JsonNode.class); String uglyStr = jsonNode.toString(); String jsonOut = parser.serialize(msgs, 0); Assert.assertEquals(uglyStr, jsonOut); jsonOut = parser.serialize(msgs.get(0), 0); Assert.assertEquals(uglyStr, jsonOut); }