I have a this object:
case class UserStateSummaryByHourPayload (
ownerid: String,
userid: String,
team: String,
profile: String,
day: String,
hour: Int,
sortdate: String,
month: String,
durationpayload: Map[String, Long],
maxdurationpayload: Map[String, Long]
)
I would like to turn the two Map attributes into JSON or a string (writing to mysql column) such as this
case class JunkTest (
ownerid: String,
userid: String,
team: String,
profile: String,
day: String,
hour: Int,
sortdate: String,
month: String,
durationpayload: String,
maxdurationpayload: String
)
I tried to do something like this following some other peoples guides, but its not working:
import com.fasterxml.jackson.module.scala.DefaultScalaModule;
import com.fasterxml.jackson.databind.ObjectMapper;
@transient val mapper = new ObjectMapper();
mapper.registerModule(DefaultScalaModule);
var junktest = ussapayloads.map(a => new JunkTest(
a.ownerid,
a.userid,
a.team,
a.profile,
a.day,
a.hour,
a.sortdate,
a.month,
mapper.writeValueAsString(a.durationpayload),
mapper.writeValueAsString(a.maxdurationpayload)
));
How to I take my Map[String, Long] and turn it into JSON or a JSON string?
Map("Online" -> 100,"Ready" -> 200)
{ "Online": 100, "Ready": 200 }