ThingsNetworkProvider extends JsonBasedLoraProvider { @Override protected Buffer getPayload(final JsonObject loraMessage) { Objects.requireNonNull(loraMessage); if (loraMessage.containsKey(FIELD_TTN_PAYLOAD_RAW) && loraMessage.getValue(FIELD_TTN_PAYLOAD_RAW) == null) { return Buffer.buffer(); } return LoraUtils.getChildObject(loraMessage, FIELD_TTN_PAYLOAD_RAW, String.class) .map(s -> Buffer.buffer(Base64.getDecoder().decode(s))) .orElseThrow(() -> new LoraProviderMalformedPayloadException("message does not contain Base64 encoded payload property")); }  @Override String getProviderName(); @Override Set<String> pathPrefixes();  }
@Test public void testGetMessageParsesUplinkMessagePropertiesWithNullPayload() throws IOException { final RoutingContext requestContext = getRequestContext(LoraMessageType.UPLINK, "with-null-payload"); final UplinkLoraMessage loraMessage = (UplinkLoraMessage) provider.getMessage(requestContext); assertThat(loraMessage.getDevEUIAsString()).isEqualTo("0102030405060708"); assertThat(loraMessage.getPayload()).isNotNull(); assertThat(loraMessage.getPayload().length()).isEqualTo(0); }