Jackson is unable to parse an ISO_INSTANT example from its documentation - jackson

Im using jackson 2.9.7, running
new ObjectMapper().findAndRegisterModules().readValue("2011-12-03T10:15:30Z", Instant.class)
Leads to an exception
Unexpected character ('-' (code 45)): Expected space separating root-level values, but the format should be correct due to https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_INSTANT
From what I can tell, it expects a timestamp(8175812123 is correctly parsed to 2229-01-30T10:55:23Z)

Related

Using the wrong escape character for Lucene lexical error at line 1 Cannot Parse Encountered <EOF>. Kentico 12

I have a similar issue as the following question: Lucene error while parsing Query: Cannot parse '': Encountered “” at line 1, column 0, and I had already tried all the escaping. What else could it be?
I'm using Kentico 12 hotfix 14, with their Lucene.NET 3.0.3 implementation. My Smart Search Index uses the Standard analyzer, see below:
I get the expected rows back when I use the following lucene syntax to pull back an en-US culture result. This syntax is automatically created by Kentico and is needed to retrieve the correct culture. This was directly copied from the property value.
"+_culture:([en-us TO en-us] [invariantifieldivaluei TO invariantifieldivaluei])"
When I add (or use alone) the following value (in many different forms - without parenthesis, etc):
"+length:(24\")"
I always get the Lexical error:
"Cannot parse '+_culture:([en-us TO en-us] [invariantifieldivaluei TO invariantifieldivaluei]) +length:(24\")': Lexical error at line 1, column 95. Encountered: <EOF> after : \"\\\")\""
As you can see, I believe that I have escaped the value for the length correctly. What am I missing here?
Other values, that don't require escaping work just fine, such as:
+material:(nitrile)
Any thoughts on what I'm doing wrong with the 24" value? Wrong analyzer? Needed Kentico hotfix? Wrong order of filters? Thanks for your time!
Seems I'm not the first to deal with this within Kentico, and found the following helper method: CMS.Search.SearchSyntaxHelper.EscapeKeyWords(string). I applied this method to my specific search filter values and it's working as expected! Lots of good methods within the parent class too, check them out.

Why Doctrine2 array type serialization fails with some special characters?

I've found an issue with array types at doctrine2.
In my app I've some users with come frome slovenia. These guys have some strange chars like "čćšž". After this value gets serialized and stored into the database the issue occurs.
After that I get following expection:
Notice: unserialize() [function.unserialize]: Error at offset 456 of 645 bytes in /Applications/MAMP/htdocs/firegames.at/vendor/doctrine-dbal/lib/Doctrine/DBAL/Types/ArrayType.php line 46
So I figured out that the following content in the serialized sting triggers the expection:
s:7:"Urani?"
But It should be Uranić. I tryied to convert the string into utf8 but it also fails. The chars cant't be encoded!
It's interresting if I replace the ? directly with the ć it works as expected. Also strange is that the char ž makes no issue. That's the only one which works.
So anyone an idea how to fix that?
What you need to do is tell DBAL to do "SET NAMES utf8" when connecting to the DB. This is done by passing the charset='utf8' parameter to the config. You might want to read the documentation, where you'll find that this is only possible with PDO MySQL and OCI (Oracle) but I assume you are using MySQL.
Additionally, did you create your table cells using CHARACTER SET utf8 COLLATE utf8_slovenian_ci?

JSON parsing with £ symbol returning null

I am trying to parse a JSON script from my server which contains a £ (pound) however this is returning null. I had problems before so temporarily just switched to using dollars or euro sign but I need to be able to parse the pound sign. However I am unsure as to how to rectify this issue. I created a test project and temporarily just using String with contents method, all the other jsons work fine, but the one with the pound sign in it returns null.
NSString *get5 = [NSString stringWithContentsOfURL:url5 encoding:NSUTF8StringEncoding error:nil];
I tried the other encoding NSUTF encoding but they dont seem to work either. Some return null, some return chinese characters, so they are not much good.
Any help would be much appreciated!!
Edit:
Used the NSError object and got this message back
"The operation couldn’t be completed. (Cocoa error 261.)"
UserInfo=0x68294b0
{NSURL=http://myserver.com/test.jsp,
NSStringEncoding=4}
Cocoa Error 261 is an encoding error. The service returning the JSON obviously isn't returning it with an UTF-8 encoding. Either make the service returns UTF-8 if you can, or find out which encoding it is returning and use that.
See this question for more info:
Encoding issue: Cocoa Error 261?
Can you check that the json is not encoded in 1) CRLF (windows)encoding 2) Western etc.
Make sure the encoding is UTF-8

IOS JSON escaping special characters

I'm working in IOS and trying to pass some content to a web server via an NSURLRequest. On the server I have a PHP script setup to accept the request string and convert it into an JSON object using the Zend_JSON framework. The issue I am having is whenever the character "ø" is in any part of the request parameters, then the request string is cut short by one character.
Request string before going to server.
[{"description":"Blah blah","type":"Russebuss","name":"Roscoe Simulator","appVersion":"1.0.20","osVersion":"IOS 5.1","phone":"5555555","country":"Østfold","udid":"bed164974ea0d436a43f3cdee0e005a1"}]
Request string on server before any parsing
[{"description":"Blah blah","type":"Russebuss","name":"Roscoe Simulator","appVersion":"1.0.20","osVersion":"IOS 5.1","phone":"5555555","country":"Nord-Trøndelag","udid":"bed164974ea0d436a43f3cdee0e005a1"}
Everything looks exactly the same except the final closing ] is missing. I'm thinking it's having an issue when converting the string to UTF-8, but not sure the correct way to fix this issue.
Does anyone have any ideas why this is happening?
first of all do not trust the xcode console in such cases. you never know which coding the console is actually using.
second, escape the invalid characters before you build you json string. easiest way would probably to make sure you are using the same unicode representation, like utf-8, all the time.
third, if there are still invalid characters use a json lib with a parser (does the encoding). validate the output by parsing back to e.g. NSString. or validate the output manually by using a web form like http://jsonformatter.curiousconcept.com/
the badest way is to replace the single characters in the string, build your json and convert back. one way to do this could be to replace e.g an german ä with its unicode representaion U+00E4 (http://www.utf8-chartable.de/).
Thats the way I do it. I am glad that I nerver needed to go further than step three and this is the step you should do anyway to keep your code simple.
Please try to use Zends internal json Encoding:
Zend_Json::$useBuiltinEncoderDecoder = true;
should fix your issue.

JSON string containing regular expression as data

I am reading JSON code from the database and then parsing the string using json parsers available for java. But I am getting JSONexception. Even if I try to parse this string on an online parser http://json.parser.online.fr/ there also the strings are taken as errors. Is there a way out to get rid of these errors or in other words how can I take care of such special symbols. The value of match is a regular expression.
Here is subpart of the sample string I am trying to parse as a json object.
{"RULE":[{"replace":{"value":"","type":"text"},"match":{"value":"<a [^>]*><img src="[^"]*WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites[^>]*>\s*</a>","type":"text"}},{"replace":{"value":"","type":"text"},"match":{"value":"<a [^>]*><img src="[^"]*WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites[^>]*>\s*</a>","type":"text"}}]}
use this json
{"RULE":[{"replace":{"value":"","type":"text"},"match":{"value":"<a [^>]*><img src=\"[^\"]*WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites[^>]*>\\s*</a>","type":"text"}},{"replace":{"value":"","type":"text"},"match":{"value":"<a [^>]*><img src=\"[^\"]*WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites[^>]*>\\s*</a>","type":"text"}}]}