modules/ballerina-native/src/main/java/org/ballerinalang/nativeimpl/connectors/jms/utils/JMSMessageUtils.java
public static BMessage toBallerinaMessage(SerializableCarbonMessage serializableCarbonMessage) {
        BMessage bMessage = new BMessage();
        HashMap<String, String> headerMap = serializableCarbonMessage.getHeadersMap();
        headerMap.forEach((key, value) -> {
            bMessage.getHeaders().add(new Header(key, value));
        });

        if (headerMap.get(Constants.CONTENT_TYPE).equals(Constants.APPLICATION_JSON)) {
            BJSON payload = new BJSON(serializableCarbonMessage.getPayload());
            bMessage.setMessageDataSource(payload);
        } else if (headerMap.get(Constants.CONTENT_TYPE).equals(Constants.APPLICATION_XML)) {
            BXML payload = new BXML(serializableCarbonMessage.getPayload());
            bMessage.setMessageDataSource(payload);
        } else if (headerMap.get(Constants.CONTENT_TYPE).equals(Constants.TEXT_PLAIN)) {
            BString payload = new BString(serializableCarbonMessage.getPayload());
            bMessage.setMessageDataSource(payload.stringValue());
        }
        return bMessage;
    }
/**
     * To convert a {@link SerializableCarbonMessage} message into a {@link BMessage}.
     *
     * @param serializableCarbonMessage {@link SerializableCarbonMessage} to be converted
     * @return Converted {@link BMessage}
     */
To convert a  SerializableCarbonMessage message into a  BMessage.
To convert a SerializableCarbonMessage message into a BMessage .
public static BMessage toBallerinaMessage(SerializableCarbonMessage serializableCarbonMessage) {
        BMessage bMessage = new BMessage();
        HashMap<String, String> headerMap = serializableCarbonMessage.getHeadersMap();
        headerMap.forEach((key, value) -> {
            bMessage.getHeaders().add(new Header(key, value));
        });
        if (headerMap.get(Constants.CONTENT_TYPE).equals(Constants.APPLICATION_JSON)) {
            BJSON payload = new BJSON(serializableCarbonMessage.getPayload());
            bMessage.setMessageDataSource(payload);
        } else if (headerMap.get(Constants.CONTENT_TYPE).equals(Constants.APPLICATION_XML)) {
            BXML payload = new BXML(serializableCarbonMessage.getPayload());
            bMessage.setMessageDataSource(payload);
        } else if (headerMap.get(Constants.CONTENT_TYPE).equals(Constants.TEXT_PLAIN)) {
            BString payload = new BString(serializableCarbonMessage.getPayload());
            bMessage.setMessageDataSource(payload.stringValue());
        }
        return bMessage;
    }
public static BMessage toBallerinaMessage ( SerializableCarbonMessage serializableCarbonMessage ) { BMessage bMessage = new BMessage ( ) ; HashMap < String , String > headerMap = serializableCarbonMessage . getHeadersMap ( ) ; headerMap . forEach ( ( key , value ) -> { bMessage . getHeaders ( ) . add ( new Header ( key , value ) ) ; } ) ; if ( headerMap . get ( Constants . CONTENT_TYPE ) . equals ( Constants . APPLICATION_JSON ) ) { BJSON payload = new BJSON ( serializableCarbonMessage . getPayload ( ) ) ; bMessage . setMessageDataSource ( payload ) ; } else if ( headerMap . get ( Constants . CONTENT_TYPE ) . equals ( Constants . APPLICATION_XML ) ) { BXML payload = new BXML ( serializableCarbonMessage . getPayload ( ) ) ; bMessage . setMessageDataSource ( payload ) ; } else if ( headerMap . get ( Constants . CONTENT_TYPE ) . equals ( Constants . TEXT_PLAIN ) ) { BString payload = new BString ( serializableCarbonMessage . getPayload ( ) ) ; bMessage . setMessageDataSource ( payload . stringValue ( ) ) ; } return bMessage ; }
To convert a {@link SerializableCarbonMessage} message into a {@link BMessage}.
To convert a { @link SerializableCarbonMessage } message into a { @link BMessage } .