I got in front of this problem while I was subscribing for data coming from an MQTT source.

Using eclipse paho library I was writing the received message:

Topic arrived 1
Message arrived [B@a8e13ab

Very starnge result…

the two lines of code were:
System.out.println("Topic arrived " + string);
System.out.println("Message arrived " + mm.getPayload());

java-logo-ruby-style

So the problem was in the second line:

bytes had to be converted in string format with the correct encoding, really simple:

System.out.println("Topic arrived " + string);

System.out.println("Message arrived " + mm.getPayload());

System.out.println("Message arrived " + new String(mm.getPayload(), "UTF-8"));

and the result is:

 

Topic arrived 1
Message arrived [B@a8e13ab
Message arrived myMessage

 

Gg1