Returning String on function shows empty string

Hey all,

I’m getting a weird behaviour on my code. I’m generating a JSON document with sensor data to send to an web API. Thing is, when I return the JSON string from my class and try to print it to Serial I get an empty String. If I do a Serial.println in the method that generated the string, I can see it properly. But if I try to print that same string from a different method (getting it from the return value) it’s empty.

I couldn’t find any documentation about it but, is there a max size to the return value? (maybe the JSON is too big and fails to copy?). At first I suspected it wasn’t returning a copy and instead for some obscure reason it was giving me a pointer. Since I clear the original String after returning it I get an empty string. But forcing a copy (with String(otherString) ) I still get it empty.

String JSONBuilder::getJSONMessage()
  m_message.replace("#_SUBMIT_TIME_#", Time.timeStr());
  Serial.println(m_message); // Prints JSON message.
  return String(m_message);

void SampleManager::publishResult()
  // Publish the JSON result
  for(int i = 0; i < RESULT_SIZE_LIMIT; i++)

  m_lastMessage = jb.getJSONMessage();
  Serial.println(m_lastMessage); // Prints empty String

  Particle.publish(m_eventName, "");