I have a string in json format but the string does not have quotes.
[{field1:value1,field2:value2}].
Now I have to convert this string into a ArrayNode using Jackson API. Because the string does not contain any quotes, it is throwing error that it is expecting double quotes. Also, I have already tried
mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
but it is throwing error for values are not inside quotes.
You should add #JsonRawValue annotation to the fields which you want to take into consideration for parsing, so it will quotes that fields accordingly.
Related
I am using set-variable to save one field from the payload into a variable. I would like to save this variable as a string, but it ends up as a JSON array. I then need to concatenate this value with a value from my local configuration file.
I need to either save the payload field as a string or convert the array into a string during concatenation. However, I can't seem to do either.
This was a misunderstanding on my part. The incoming payload was an array so this field was an array. I wrapped it in a foreach and everything worked.
When I try to feed a string to Aurelia from a template and the string contains HTML entities representing the same quoting character as those surrounding the string, I get parser errors. Apparently the HTML enitities are interpreted before they reach Aurelia, but I'm not sure shy.
For example:
${"Why wouldn't "this" work?"}
Results in
Error: Parser Error: Unconsumed token this at column 15 in expression ["Why wouldn't "this" work?"]
Could somebody tell me why entities are interpreted rather than just outputted to the DOM? And what can I do to get this to work?
it seems aurelia parser interprets " like equivalent to ".
This makes your expression look incorrect to the parser.
You should escape the " quotes like this:
${"Why wouldn't \"this\" work?"}
Regards.
I want to serialize and deserialize objects like java Date or UUID to and from String.
The problem is that it surrounds the String itself with double quotes:
String s = objectMapper.writeValueAsString(date);
System.out.println("String: ##" + s + "##"); // String: ##"2017-12-06T04:50:30Z"##
...
Date d = objectMapper.readValue(s, Date.class); // Expects the String to be "\"2017-12-06T04:50:30Z\""
Is there a way to configure the object mapper to not use/expect the redundant double quotes?
If anyone faces the same problem: I didn't find any other way but an ugly workaround. I just remove/add the quotes to the string after/before passing it to the object mapper.
When I save a string to redis using ServiceStack.Redis:
client.Add("key1","abc");
While fetching the value, it returns:
client.GetValue("key1");
it returns
"\"abc\""
How do I get the complete string?
Thanks
It appears as though the client.Add() method converts the value to a string (even strings) and wraps them in quotes. The client.SetValue() method only accepts strings and does not wrap them in quotes.
One option would be to convert the value into a string yourself. Either via the common ToString() method, or another method to get the needed string from the object.
If the Add() method is necessary however. You could opt to check if the string is wrapped in quotes when you get it via GetValue() and if so, remove them.
Redis converts string to JSON when saving, that's why it's wrapped in quotes.
So you have to treat this string as JSON object and parse it afterwards manually or using deserialization.
I tried writing the following TestCase for an NUnit test written in VB.net:
<TestCase("FirstNode", "<node id=\"FirstNode\">")>
Public Sub GetNode_GivenSomeNodeId_ReturnCorrectNode(ByVal nodeId as String,
ByVal expectedXml as String)
(Call the method under test and request the xmlNode with the provided id...)
Assert.AreEqual(expectedXml, returnedXml)
End Sub
The xml-node passed as the second parameter to the testcase is not valid however, as this clearly is not the correct way to escape double quotes. I'm sure I can find a workaround in order to check that the method under test returns the expected XML-node, but I'm curious:
Is there some clever way to pass a string such as this, containing double quotes, as a parameter to an NUnit test?
The correct way to escape double-quotes in VB is by doubling the double-quotes:
<TestCase("FirstNode", "<node id=""FirstNode"">")>