-
Notifications
You must be signed in to change notification settings - Fork 666
Closed
Labels
Description
I want to write a string which represents nested JSON object to disk and get beginning indexes of some inner objects. The problem is that I store an inner object as string, not JSON object, in order to ensure that a digital signature function will always receive the same input. When I encode the most outer object to string, the inner one becomes escaped and I can't find initial un-escaped version in the resulting string. Consider the following example:
val messageContent = MessageContent(
type = "createGroup",
groupTitle = "Test title",
timestamp = 0
)
val messageContentString = Json.encodeToString(messageContent)
{
"type":"createGroup",
"timestamp":0,
"groupTitle":"My title"
}
val signedMessage = SignedMessage(
contentString = messageContentString,
memberPublicKey = "xxx",
contentSignature = "yyy"
)
val signedMessageString = Json.encodeToString(signedMessage)
{
"contentString":"
{
\"type\":\"createGroup\",
\"timestamp\":0,
\"groupTitle\":\"My title\"
}",
"memberPublicKey":"xxx",
"contentSignature":"yyy"
}
I'm trying to search messageContentString in signedMessageString but it's escaped with backslashes and my search fails.
Is there a way to un-escape resulting string so I can search inside it, or should I stop storing JSON objects as strings in general? Thanks.