private String encodeBatch ( Batch < String > batch ) throws IOException { // Convert original json object to a new json object with format {"Body": "originalJson"} // Add new json object to an array and send the whole array to eventhub using REST api // Refer to https://docs.microsoft.com/en-us/rest/api/eventhub/send-batch-events List < String > records = batch . getRecords ( ) ; ArrayList < EventhubRequest > arrayList = new ArrayList <> ( ) ; for ( String record : records ) { arrayList . add ( new EventhubRequest ( record ) ) ; } return mapper . writeValueAsString ( arrayList ) ; }
Each record of batch is wrapped by a Body json object put this new object into an array encode the whole array